-1

I'm passing a string in one class to a UILabel in my view controller class. For some reason the string isn't being passed. when I check whats in the string it is 0x0

class.m

[[NSNotificationCenter defaultCenter] postNotificationName:@"notification"
                                                    object:self];

somestring = @"...";

ViewController.m

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleData:)
                                             name:@"notification"
                                           object:nil];

}
- (void)handleData:(NSNotification *)notification {


[[NSOperationQueue mainQueue] addOperationWithBlock:^{

    self.timerLabel.text =somestring;

}];
}
user3219182
  • 69
  • 2
  • 10

1 Answers1

1

You look to have a few issues:

I'm not sure why you are using class in self.class.somestring, I would expect it just to be self.somestring. If you have added a class method then the naming and intention is poor.

The notification object is a controller instance, so, using self.class.somestring = notification.object; will store that controller instance. Not a string. So, when you later do lableinthisclass.text = self.class.somestring; you are treating the controller instance as a string and getting an exception.

Consider whether the class interaction is correct and use a string where your code expects a string.

Wain
  • 118,658
  • 15
  • 128
  • 151