2013-05-07 84 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]; 

這將陣列中的預分配足夠的空間來容納你所有的訊息。