2011-03-23 6 views
5

뷰가로드되어 NSMutableArray에 호출 내용을 저장할 때 웹 서비스를 호출하는 경우가 있습니다. 그런 다음 cellForRowAtIndexPath에서이 배열에서 행을 검색합니다. 나는 그러나, indexPath에서 행 인덱스를 얻을 수있는 해킹 기분을 사용indexPath의 행 인덱스

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    <snip cell alloc stuff> 

    // Configure the cell. 
    unsigned int *indexes = (unsigned int*)calloc([indexPath length], sizeof(unsigned int)); 
    [indexPath getIndexes:indexes]; 
    Tasks *task = [_tasksArray objectAtIndex:indexes[1]]; 
    free(indexes); 

    cell.textLabel.text = [task getname]; 
    cell.detailTextLabel.text = [NSString stringWithFormat:@"Started: %@", [task getstarted] ? [[task getstarted] description] : @"Not Yet"]; 

    return cell; 
} 

이 작업을 수행 할 수있는 더 나은 방법이 있나요?

답변

13

봅니다 여기 NSIndexPath 애플의 문서에 link은 년대 indexPath

indexPath.row 

의 행 부분에 액세스 할 수 있습니다.

+0

쿨, 고마워. 나는 그것이 쉽다는 것을 알고 있었지만 NSIndexPath의 내부에 대해 읽었으며 속성을 보지 못했습니다. –

+0

NSIndexPath를 검색 할 경우 설명서에 NSIndexPath Class Reference가 첫 번째로 표시되어 오해의 소지가 있습니다. –

관련 문제