Domanda

I have UIViewController that performs a login check with the code below, and a UITableViewController as its parent controller. I'm trying to add another row to the UITableViewController after switching back to it, however I'm getting the following error:

[UINavigationController insertNewObject:]: unrecognized selector sent to instance 0x14de164d0
2014-03-08 17:00:27.379 MyApp[2562:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController insertNewObject:]: unrecognized selector sent to instance 0x14de164d0'

-

if(loginSuccess)
{
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController performSelector:@selector(insertNewObject:) withObject:@"Another Row"];
}

The method definition of insertNewObject is:

- (void)insertNewObject:(NSString *)name
{
    if (!_objects) {
        _objects = [[NSMutableArray alloc] init];
    }
    [_objects insertObject:name atIndex:0];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

Can someone help me with what I'm doing wrong?

È stato utile?

Soluzione

You're calling insertNewObject on a UINavigationController not your UITableViewController.

Try creating a property on your UIViewController that points to the original TableViewController and calling it through the property. Or calling it when the TableViewController reappears.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top