Question

what wrong with this code...

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MySubViewNotification:) name:@"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'

No correct solution

OTHER TIPS

Your method called by the notification should have the signature:

- (void)mySubViewNotification:(NSNotification *)note

(note the lower case first letter - standards - class names start with capitals, methods with lower case, update your code accordingly, and the parameter being a notification)

Then you can add, in the method:

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

because the notification is passed to you as a parameter and you need to get the enclosed information (the label in this case) from it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top