gpt4 book ai didi

objective-c - 来自 indexPath 的行索引

转载 作者:可可西里 更新时间:2023-11-01 03:38:24 25 4
gpt4 key购买 nike

我经常在加载 View 时调用 Web 服务,并使用调用的内容保存一个 NSMutableArray。然后在 cellForRowAtIndexPath 中,我从该数组中检索行。然而,我使用感觉像是 hack 的方法从 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;
}

有更好的方法吗?

最佳答案

尝试访问indexPath的行部分

indexPath.row

这是一个 link Apple 文档 NSIndexPath .

关于objective-c - 来自 indexPath 的行索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5408089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com