私はこのチュートリアルに従っています:
http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server#comments
メッセージの受信というタイトルのヘッダーの最後に到達しました。チュートリアルに記載されていることをすべて実行した後でも、最初のページでユーザー名を入力してボタンを押すと、このエラーが発生します。これが私のpythonサーバーの問題なのか、実際のiOSコードの問題なのかはわかりません。Python サーバーは、reactor を使用して標準の TCP ポート 80 でリッスンします。
2013-07-19 17:10:13.450 Chat Client[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> 0x1C5CAFE 0x1C5CA3D 0x1C3A7C2
エラーは、次のコードの一部で見つかると思います。
- (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");
}
}