写入TextView覆盖以前的写入

时间:2011-05-02 15:53:42

标签: objective-c

我在IB中创建了一个TextView ...我想写两个“段落”,这似乎有用,除了第二个写覆盖第一个。

我该如何解决这个问题?

首先写:

resultText.text =[NSString stringWithFormat:@"Decode Data:  %@, \n%@\n\n",symbol.data, symbol.typeName];  //  display it...

第二次写:

    resultText.text = [NSString stringWithFormat:@"\nDatabase: \n%@ \n%@ \n%@", 
        [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)],
        [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)],
        [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]];

1 个答案:

答案 0 :(得分:0)

在我看来,你只是将文本分配两次,而不是附加。解决这个问题的简单方法是将第二次写入更改为:

resultText.text = [NSString stringWithFormat:@"%@\nDatabase: \n%@ \n%@ \n%@", 
    resultText.text,
    [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)],
    [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)],
    [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]];

这将保留您之前的文字。

编辑:

resultText.text =[NSString stringWithFormat:@"Decode Data:  %@, %@",symbol.data, symbol.typeName];

resultText.text = [NSString stringWithFormat:@"%@\nDatabase: %@, %@, %@", 
    resultText.text,
    [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)],
    [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)],
    [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)]];