Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
Iphone 访问Objective-C/Cocoa Touch阵列_Iphone_Objective C_Cocoa Touch_Arrays - Fatal编程技术网

Iphone 访问Objective-C/Cocoa Touch阵列

Iphone 访问Objective-C/Cocoa Touch阵列,iphone,objective-c,cocoa-touch,arrays,Iphone,Objective C,Cocoa Touch,Arrays,我正在使用Cocoa Touch构建一个iPhone应用程序 我有一个名为stories的NSMutableArray,在打印到控制台时显示如下内容: 2009-07-20 12:38:30.541 testapp[4797:20b] ( { link = "http://www.testing.com"; message = "testing"; username = "test"; }, { link = "http://www.testing

我正在使用Cocoa Touch构建一个iPhone应用程序

我有一个名为stories的NSMutableArray,在打印到控制台时显示如下内容:

2009-07-20 12:38:30.541 testapp[4797:20b] (
    {
    link = "http://www.testing.com";
    message = "testing";
    username = "test";
},
    {
    link = "http://www.testing2.com";
    message = "testing2";
    username = "test2";
} )
我的问题是,如何循环数组,例如每次打印'link'的值?在PHP中,我熟悉简单的数组[item]——Objective-C中有类似的方法吗?我想循环遍历数组,最终将数据放入UITableView

提前谢谢


本吉

我认为你把两件事混为一谈了。您想知道如何遍历集合(在本例中为数组),以及如何在字典中查找键

目标C为集合中的对象提供一个集合迭代循环,该循环将遍历数组或字典中的每个对象。如果是字典,它将返回映射到对象的键

对于数组,每个元素都是一个字典,因此我们可以使用NSDictionary的-objectForKey:查找链接的值并打印它:

for (NSDictionary *story in stories) {
  NSLog(@"%@", [story objectForKey:@"link"]);
}