这段代码有什么问题...
[选择器名称:@NSNotificationCenter(MySubViewNotification:) defaultCenter:@“MySubViewNotification”object: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'发布于 2014-02-22 07:51:35
您的通知调用的方法应具有签名:
- (void)mySubViewNotification:(NSNotification *)note(请注意,第一个字母小写的标准类名称以大写开头,方法以小写开头,相应地更新代码,参数为通知)
然后,您可以在该方法中添加:
UILabel *label = note.object;
label.textColor = [UIColor whiteColor];因为通知是作为参数传递给您的,您需要从它获取封装的信息(在本例中是标签)。
https://stackoverflow.com/questions/21947477
复制相似问题