Ios 将行从子级添加到UITableViewController
我有一个Ios 将行从子级添加到UITableViewController,ios,uitableview,unrecognized-selector,Ios,Uitableview,Unrecognized Selector,我有一个UIViewController,它使用下面的代码执行登录检查,还有一个UITableViewController作为它的父控制器。切换回UITableViewController后,我试图将另一行添加到该行,但出现以下错误: [UINavigationController insertNewObject:]: unrecognized selector sent to instance 0x14de164d0 2014-03-08 17:00:27.379 MyApp[2562:60b
UIViewController
,它使用下面的代码执行登录检查,还有一个UITableViewController
作为它的父控制器。切换回UITableViewController
后,我试图将另一行添加到该行,但出现以下错误:
[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'
-
insertNewObject的方法定义为:
- (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];
}
有人能帮我解决我做错了什么吗?您在
UINavigationController
上调用的是insertNewObject
,而不是UITableViewController
尝试在UIViewController上创建一个指向原始TableViewController的属性,并通过该属性调用它。或者在TableViewController重新出现时调用它
- (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];
}