gpt4 book ai didi

ios - (self.nsmutablearray)[indexPath.row] 是什么意思?

转载 作者:行者123 更新时间:2023-11-29 02:38:03 25 4
gpt4 key购买 nike

我正在为学习目的开发一个联系人列表,这个问题是在学习时出现的。

问题是: 我正在为我的 TableView 配置一个单元格,我的一个 friend 说我应该使用 (self.nsmutablearray)[indexPath.row],但我不明白为什么我应该在 [indexPath.row] 之前使用 (self.nsmutablearray)。我知道这是一个愚蠢的问题,但我就是不明白编程范式究竟是如何工作的。代码如下(Contact 是一个 NSObject,contactList 是一个 NSMutablArray):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ContactCell" forIndexPath:indexPath];
Contact *contact = (self.contactList)[indexPath.row];

cell.textLabel.text = contato.name;

return cell;
}

最佳答案

是索引订阅。

self.contactList 表示一组 Contact 对象。您需要获取表中特定行的联系人,以便可以用数据填充单元格。 indexPath 表示表中的一个部分和行,indexPath.row 仅表示行。因此,您可以编写 self.contactList[indexPath.row] 从数组中检索该索引处的元素。

或者,您可以编写 [self.contactList objectAtIndex:indexPath.row]

关于ios - (self.nsmutablearray)[indexPath.row] 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26131310/

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