0

我正在关注本教程:

http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server#comments

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

2013-07-19 17:10:13.450 聊天客户端 [3505:c07] * 断言失败 -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:5471 2013-07-19 17 :10:13.451 聊天客户端[3505:c07]Terminating app due to uncaught exception >'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from >tableView:cellForRowAtIndexPath:' * * First throw call stack: (0x1c94012 0x10d1e7e 0x1c93e78 0xb67665 0xcbc1b 0x6040c 0xcba7b 0xd0919 0xd09cf 0xb91bb >0xc9b4b 0x662dd 0x10e56b0 0x2290fc0 0x228533C 0x2285150 0x22030BC 0x2204227 0x22048E2> 0x1C5C5C5CAFE 0x1C5CA3D 0x1C3A7C2 0X1C399F44 40x1C39e1BROTH thr

我相信可以在此处的某些代码中找到错误:

- (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");
    }
}
4

0 回答 0