Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将NSDictionary中的所有内容放入UITextView_Ios_Objective C_Nsdictionary - Fatal编程技术网

Ios 将NSDictionary中的所有内容放入UITextView

Ios 将NSDictionary中的所有内容放入UITextView,ios,objective-c,nsdictionary,Ios,Objective C,Nsdictionary,我得到了一个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 tex

我得到了一个
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"]);
}

for(int i=0;i您应该将其附加到现有文本中

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"]);
}
textview.text=@”;

对于(int i=0;i而言,问题在于
textview.text
正在覆盖
textview.text
的先前内容

您需要做的是将字符串附加到
textview
的现有值:

textview.text=[textview.text stringByAppendingString:[DictionObjectForkey:@“text”]];

但这将同时获得所有值,因此您可能希望在值之间添加一个空格:

NSString*appendedText=[nsstringstringwithformat:@“%@%@”,textview.text,[diction objectForKey:@“text”];
textview.text=附录文本;


最后,您可以使用现代Objective-C文本访问字典对象,如
array[i]
diction[@“text”]
而不是使用
objectAtIndex
objectForKey
来减少键入量。

当您设置
textview时。text
覆盖该属性之前的任何设置。因此,您只能看到循环中设置的最后一个。为什么要使用两个格式化程序?为什么不只是
textview.text=[textview.text stringByAppendingFormat:@“%@\n”,措辞[@“text]”;
?更新后,我更习惯于创建
NSString stringWithFormat
。但在检查时,我刚刚复制了appendingFormat,以前使用AppendingStringGi,我怀疑OP希望将“text”值放在单独的行上。