当视图加载并保存带有调用内容的NSMutableArray时,我经常调用Web服务。然后在cellForRowAtIndexPath中,我从这个数组中检索行。我使用感觉像黑客来从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;
}
有更好的方法吗?