0

(我正在开发一个在表格中显示聊天消息的应用程序。但是,用户无法启动此聊天,当用户收到消息时,聊天视图会打开。所以,我编写了以下代码:

- (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'

我认为解决第一个异常可以解决我的问题。有什么帮助吗?

谢谢你。

4

2 回答 2

1
In the second exception i think you have called [self setTableViewStyle:] method, while   

you have made it UIViewController.

So try to call this method by tableViewOutlet.

[tableView setTableViewStyle:];

希望对你有帮助

于 2012-06-13T14:46:44.107 回答
0

解决了。我单击 .xib 文件,在“对象”下,单击“查看”。然后,在 Identity Inspector(第三个,从左边开始)中,在 Custom Class 中,将其设置为 UITableView。以前只是“查看”。然后,一切正常。

于 2012-06-13T13:00:01.663 回答