(我正在开发一个在表格中显示聊天消息的应用程序。但是,用户无法启动此聊天,当用户收到消息时,聊天视图会打开。所以,我编写了以下代码:
- (void) newMessageReceived:(NSMutableDictionary *)message
{
General *general = [General sharedManager];
NSString *firstmessage=[message objectForKey:@"msg"];
NSString *from=[message objectForKey:@"sender"];
NSArray *listItems = [from componentsSeparatedByString:@"@"];
NSString *fromsplit=[listItems objectAtIndex:0];
general.firstmess=firstmessage;
general.firstfrom=fromsplit;
NSLog(@"Mensaje recibido: %@ de %@", [message objectForKey:@"msg"], fromsplit);
ChatViewController *cvc=[[ChatViewController alloc]initWithNibName:@"Chat" bundle:nil];
[[self navigationController]pushViewController:cvc animated:YES];
}
一切都很好,直到这里。ChatViewController 扩展了 UITableViewController。但是,当收到一条消息时,我得到以下异常:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "Chat" nib but didn't get a UITableView.
然后,我尝试更改扩展为 UIViewController 的类(这样做是为了检查程序是否输入了 numberOfRowsInSection 方法),然后我收到:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChatViewController setTableViewStyle:]: unrecognized selector sent to instance 0x9863200'
我认为解决第一个异常可以解决我的问题。有什么帮助吗?
谢谢你。