OGeek|极客世界-中国程序员成长平台

标题: ios - 将 NSDictionary 中的所有内容放入 UITextView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 20:01
标题: ios - 将 NSDictionary 中的所有内容放入 UITextView

我有一个 NSDictionary,我想将它打印到 UITextView

我尝试使用此代码,但是当我尝试将其放入 UITextView 时,它只会得到一行文本,而当我 NSLog 时,它可以完美运行。

for(int i=0; i<[array count];i++) {
    dictionary = [array objectAtIndex:i];
    //that shows only one line from the dictionary in the textview
    textview.text = [dictionary objectForKey"text"];

    //that shows all the dictionary with key "text" in the log
    NSLog(@"%@", [dictionary objectForKey"text"]);
}

有没有办法解决这个问题?



Best Answer-推荐答案


您应该将其附加到现有文本中

textview.text = @"";

  for(int i=0; i<[array count];i++)
{
        dictionary= [array objectAtIndex:i];
        //that shows only one line from the dictionary in the textview
        textview.text = [textview.text stringByAppendingFormat"%@\n",[diction objectForKey"text"]]];

        //that shows all the dictionary with key "text" in the log
        NSLog(@"%@",[diction objectForKey"text"]);
}

关于ios - 将 NSDictionary 中的所有内容放入 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22356595/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4