2011-05-02 99 views
0

我有一个在IB创建的TextView ...我有两个“段落”我想写,似乎工作,除了第二次写入覆盖第一个。写入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)]]; 
+0

所以你的问题是,“数据库...”字符串覆盖“解码数据......”字符串?另外,这是你正在谈论的UITextView? – 2011-05-02 15:56:28

回答

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)]]; 
+0

Dan ...它分割文本,在text1的数据之前给出text2的标题,然后给出text2的数据。 – SpokaneDude 2011-05-02 16:12:48

+0

你能举一个例子,说明文字是什么以及你想如何显示它?也许我不明白你想要完成什么 – 2011-05-02 16:14:22

+0

解码数据:字段1,字段2,字段3 数据库:字段4,字段5,字段6 – SpokaneDude 2011-05-02 16:24:01