使用Python进行基于iOS开发套接字的流编程-UITableView错误

使用Python进行基于iOS开发套接字的流编程-UITableView错误,ios,uitableview,assertion,Ios,Uitableview,Assertion,我将学习本教程: 我已到达标题为“接收消息”的标题的末尾。 即使完成了教程中所述的所有操作,当我在第一页输入用户名并按下按钮时,也会收到此错误。我不确定这是我的python服务器的问题还是实际的iOS代码的问题。python服务器使用reactor侦听标准TCP端口80 2013-07-19 17:10:13.450聊天客户端[3505:c07]*在-[UITableView\u configureCellForDisplay:forIndexPath:],/SourceCache/UIKit

我将学习本教程:

我已到达标题为“接收消息”的标题的末尾。 即使完成了教程中所述的所有操作,当我在第一页输入用户名并按下按钮时,也会收到此错误。我不确定这是我的python服务器的问题还是实际的iOS代码的问题。python服务器使用reactor侦听标准TCP端口80

2013-07-19 17:10:13.450聊天客户端[3505:c07]*在-[UITableView\u configureCellForDisplay:forIndexPath:],/SourceCache/UIKit\u Sim/UIKit-2380.17/UITableView.m:5471中断言失败 2013-07-19 17:10:13.451聊天客户端[3505:c07]由于未捕获的异常而终止应用程序>'nSinternalinconsistenceexception',原因:“UITableView数据源必须从>tableView:cellForRowAtIndexPath:返回单元格” **第一次抛出调用堆栈: (0x1c94012 0x10d1e7e 0x1c93e78 0xb67665 0xcbc1b 0x6040c 0xcba7b 0xd0919 0xd09cf 0xb91bb>0xc9b4b 0x662dd 0x10E56B00x2290FC0 0x228533c 0x2285150 0x22030bc 0x2204227 0x22048e2>0x1c5cafe 0x1c5ca3d 0x3A 7C2 0x1c39f44 0x1c39e1b 0x1BEEE668 0x15ffc 0x244d 0x2375) libc++abi.dylib:terminate调用引发异常

我相信在以下代码中可以找到错误:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtInexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"ChatCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    NSString *s = (NSString *) [messages objectAtIndex:indexPath.row];
    cell.textLabel.text = s;

    return cell;
}

-(void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
    NSLog(@"stream event %i", streamEvent);

    switch (streamEvent) {

        case NSStreamEventOpenCompleted:
            NSLog(@"Stream opened");
            break;

        case NSStreamEventHasBytesAvailable:

            if (theStream == inputStream) {

                uint8_t buffer[1024];
                int len;

                while([inputStream hasBytesAvailable]) {

                    len = [inputStream read:buffer maxLength:sizeof(buffer)];
                    if(len>0) {
                        NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];

                        if (nil != output) {
                            NSLog(@"server said: %@", output);
                            [self messageReceived:output];
                        }
                    }
                }
            }
        break;

        case NSStreamEventErrorOccurred:
            NSLog(@"Can not connect to the host!");
            break;

        case NSStreamEventEndEncountered:
            break;

        default:
            NSLog(@"Unknown event");
    }
}

这个错误非常简单。它表示您没有从tableView:cellForRowAtIndexPath:method返回单元格。看起来你是。。。那么,您是否在tableView:cellForRowAtIndexPath:中设置了断点并再次检查是否调用了该断点?没有。我应该在哪里检查它是否被呼叫?我对iOS开发相当陌生。当收到消息时,会发生此事件的初始触发,如-(void)stream:(NSStream*)在[self messageReceived:output]上的“nsstreamventhasbytesavailable:”情况下的流中所示;messageReceived方法调用[messages addObject:message];和[self.tView重新加载数据];其中tView是表视图,messages是一个NSMutableArray,用于存储聊天信息。