开发者

Row index from indexPath

I often call a web service when a view loads and save an NSMutableArray with the contents of the call. Then in cellForRowAtIndexPath I retrieve the rows from this array. I use what feels like a hack to get the row index from the indexPath, however:

- (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 );

    cel开发者_运维知识库l.textLabel.text = [task getname];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"Started: %@", [task getstarted] ? [[task getstarted] description] : @"Not Yet"];

    return cell;
}

Is there a better way to do this?


Try to access the row part of the indexPath

indexPath.row

Here's a link to Apple's documentation for NSIndexPath.


You should be able to use the row property from NSIndexPath UIKit Additions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜