在项目开发过程中碰到[xxx objectForKey:]: unrecognized selector sent to instance 错误, 具体情形是这样的,在一个NSMutableArray *array = [NSMutableArray alloc ] init];
NSMyClassOne *obj1 = [[NSMyClassOne alloc] init];
[array addobject: obj1];
NSMyClassTwo *obj2 = [[NSMyClassTwo alloc] init];
[array addobject: obj2];
[myTableView reloadData];
每次调用[myTableView reloadData];
即提示:
2013-06-26 11:54:40.973 CIRI[3651:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[obj1 objectForKey:]: unrecognized selector sent to instance 0x1e968f30'
*** First throw call stack:
原因是因为在TableViewController里边没有提供数据源的方法中所需要的数据:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath