2011-05-02 23 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