Я пытаюсь использовать NSNotification. Я создаю NSDictionary на основе того, какая из моих кнопок была нажата в представлении. Когда я NSLog тег, тег является правильным. Поэтому я использую оператор switch, как этот, чтобы создать свой словарь:
NSDictionary *dict;
switch (tag) {
case 0:
dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:tag] forKey:@"ButtonType"];
break;
case 1:
dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:tag], @"ButtonType", nil];
break;
case 2:
dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:tag], @"ButtonType", nil];
break;
case 3:
dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:tag], @"ButtonType", nil];
break;
case 4:
dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:tag], @"ButtonType", nil];
break;
default:
NSLog(@"No dictionary set for ButtonType");
break;
}
[[NSNotificationCenter defaultCenter] postNotificationName:(ShowData:) object:self userInfo:dict];
А затем в ShowData:
- (void)ShowData:(NSNotification *)notification {
NSLog(@"%s", __FUNCTION__);
NSDictionary *userDict = [notification userInfo];
NSInteger theTag = (NSInteger)[userDict objectForKey:@"ButtonType"];
NSLog(@"tag: %i", theTag); // this value is incorrect
В моем методе ShowData я ожидал бы те же значения тега, 0-4, но вместо этого я получаю что-то вроде: 187742848. Когда я перехожу через отладчик, я вижу, что мой userInfo NSDictionary устанавливается в значение, которое передается , Я не создаю свой NSDictionary правильный, чтобы передать ShowData:? Спасибо.