Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSNotificationCenter对象UILabel_Objective C_Ios7_Xcode5_Nsnotificationcenter - Fatal编程技术网

Objective c NSNotificationCenter对象UILabel

Objective c NSNotificationCenter对象UILabel,objective-c,ios7,xcode5,nsnotificationcenter,Objective C,Ios7,Xcode5,Nsnotificationcenter,这个代码有什么问题 [[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selectorMySubViewNotification:名称:@MySubViewNotification对象:nil] -(void)MySubViewNotification:(UILabel*)GenericLabel { GenericLabel.textColor = [UIColor whiteColor]; ---- Error ----

这个代码有什么问题

[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selectorMySubViewNotification:名称:@MySubViewNotification对象:nil]

 -(void)MySubViewNotification:(UILabel*)GenericLabel
 {

    GenericLabel.textColor = [UIColor whiteColor]; ---- Error ----
    GenericLabel.text = @"cwxcwxc"; ---- Error ----

    NSLog(@"%@", GenericLabel);
 }

 NSLog.

 NSConcreteNotification 0x1759c6c0 {name = MySubViewNotification; object = <UILabel: 0x175aace0; frame = (175 5; 62 15); text = '1.35'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x175aad80>>}

 Errror

-[NSConcreteNotification setText:]: unrecognized selector sent to instance 0x165a4270
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteNotification setText:]: unrecognized selector sent to instance 0x165a4270'

通知调用的方法应具有以下签名:

- (void)mySubViewNotification:(NSNotification *)note
请注意,小写的第一个字母-标准-类名以大写字母开头,方法以小写字母开头,相应地更新代码,参数为通知

然后,您可以在方法中添加:

UILabel *label = note.object;
label.textColor = [UIColor whiteColor];

因为通知是作为一个参数传递给您的,您需要从中获取标签附带的信息。

谢谢,但添加了通知错误[NSNotificationCenter defaultCenter]addObserver:self selector:@selectorMySubViewNotification:name:@MySubViewNotification object:nil];我不理解你的评论。当我创建通知时,[[NSNotificationCenter defaultCenter]addObserver:self selector:@selectorMySubViewNotification:name:@MySubViewNotification对象:nil];我***由于未捕获的异常“NSInvalidArgumentException”而终止了应用程序,原因:'-[MasterViewController MySubViewNotification:]:无法识别的选择器发送到实例0x15d4bcf0',因为您尚未更正命名标准小写字母的方法的名称