如何使UItableview具有格式长度 [英] how to make UItableview to be with format length

查看:79
本文介绍了如何使UItableview具有格式长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个作业,我必须从NSInputstream接收传入的消息并必须在UItableview中查看它,我可以接收消息并正确发送消息,但是有时我的字符串甚至在同一行中编写虽然我输入\ n.

I am doing a homework where i have to receive the incoming message from the NSInputstream and have to view it in UItableview, i can receive the message and send the message properly , but some time my string is writing in the same line even though i give in \n.

有人有主意吗????

do any one have idea ????

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

for example:
@abc:123:123:123:123@
@abc:123:123:123:123@
@abc:1:2:3@

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

first line prints in the first row but in second row prints third line also , can any one tell me how to make a format where if string starts and ends with "@" will write in each row not in the same row.

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

i made lots of filter message but it fails

我的代码:

    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 @


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

但是我期待着w:

@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@

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

.... if the string starts and ends with "@" has to write in the next line... the problem is because the some time string is small so it takes the same line , but i want it in the next line if starts and ends with "@"

推荐答案

您可以按组件分开使用数组.

You can make use of array by separated by components..

    NSString* string = @"@abc:123:123:123:123@@abc:123:123:123:123@123:123:123:1@abc:1:2:3@123:123:123:1@abc:123:123:123:123@@abc:123:123:123:123@ 123:123:123:1@abc:1:2:3@ @abc:123:123:123:123@@abc:123:123:123:123@123:123:123:1@abc:1:2:3@ 123:123:123:1@abc:123:123:123:123@123:123:123:1@abc:123:123:123:123@123:123:123:1@abc:1:2:3@";

NSMutableString* formatString = [NSMutableString string];

NSArray* strArr = [string componentsSeparatedByString:@"@"];
for (NSString* str in strArr)
{
    [formatString appendFormat:@"%@@\n@",str];
}
NSLog(@"%@",formatString);

这篇关于如何使UItableview具有格式长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆