2013-05-07 5 views
1

Post이라는 NSObject 클래스가 있습니다. post의 속성은 URL입니다. 응용 프로그램이 시작되면 URL로 새 게시물이 만들어지고 _objects라는 배열에 추가됩니다. 표 셀을 선택하면 post.url_objects[indexPath.row]에 설정하고 싶습니다.배열에 객체의 속성을 가져옵니다.

테이블에 추가 :

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; 

내가 셀이 반환 또는 무언가 시뮬 선택 _objects[indexPath.row]를 호출하면

.

답변

2

이것이 필요한가요?

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

또한 조금 더 효율적이로 코드의 첫 번째 라인을 교체하여 만들 수 있습니다 : 이것은 모든 게시물을 개최 배열에 충분한 공간을 미리 할당합니다

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

.

관련 문제