0

我正在做作业,我必须从 NSInputstream 接收传入的消息,并且必须在 UItableview 中查看它,我可以接收消息并正确发送消息,但有时我的字符串写在同一行,即使我给客栈。

有人知道吗????

例如:
@abc:123:123:123:123@
@abc:123:123:123:123@
@abc:1:2:3@

第一行打印在第一行,但在第二行也打印第三行,谁能告诉我如何制作一个格式,如果字符串以“@”开头和结尾将写在每一行中,而不是在同一行中。

我做了很多过滤消息,但它失败了

我的代码:

    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);
                    }
                }
            }
        }
        break;
NSIndexPath *topIndexPath = [NSIndexPath indexPathForRow:messages.count-1 inSection:0];
[self.tView scrollToRowAtIndexPath:topIndexPath 
                  atScrollPosition:UITableViewScrollPositionMiddle 
                          animated:YES];

输出:
@abc:123:123:123:123@
@abc:123:123:123:123@ @abc:1:2:3@

但我期待:

@abc:123:123:123:123@
@abc:123:123:123:123@
@abc:1:2:3@

....如果字符串以“@”开头和结尾必须写在下一行...问题是因为某个时间字符串很小所以它占用同一行,但我希望它在下一行如果以“@”开头和结尾

4

0 回答 0