0

I have a view controller based UITableViewController, I want to reload the table view when receive update notification:

    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateApStatus:) name:@"UpdateApStatus" object:nil];
    }


- (void)updateApStatus{
    NSLog(@"......updateApStatus......");
    [self.tableView reloadData];
}

And I post notification in other class:

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

The error is :

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MenuViewController updateApStatus:]: unrecognized selector sent to instance 0xb25bf80'

It seems like i can not access self

why
  • 23,923
  • 29
  • 97
  • 142

1 Answers1

1

Remove the ":" from updateApStatus. You will only use a colon if the function has parameters which is not so in your case. Therefore adding the colon is a different selector completely which is why it is unrecognized.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateApStatus) name:@"UpdateApStatus" object:nil];
avenger
  • 120
  • 5