2013-05-07 83 views
1

我有一个NSObject类叫做Post。 A post有财产URL。当我的应用程序开始时,使用URL创建新帖子并添加到名为_objects的数组中。当选择表格单元格时,我想在_objects[indexPath.row]中设置post.url从数组中获取对象的属性它在

添加到表:

NSMutableArray *newPosts = [[NSMutableArray alloc] initWithCapacity:0]; 
for (SomeElement *element in postNodes) { 

    Post *post = [[Post alloc] init]; 
    [newPosts addObject:post]; 

    post.title = [[element firstChild] content]; 

    post.url = [element objectForKey:@"href"]; 
} 

_objects = newPosts; 

如果我打电话的时候,选择了小区返回什么simular _objects[indexPath.row]

回答

2

这是你所需要的?

Post *post = _objects[indexPath.row]; 
[something setURL:post.url]; 

你也可以把它一点点高效用这个替换您的代码段的第一行:

NSMutableArray *newPosts = [[NSMutableArray alloc] initWithCapacity:postNodes.count]; 

这将阵列中的预分配足够的空间来容纳你所有的讯息。