gpt4 book ai didi

iphone - 具有不同值的 TableView 委托(delegate)方法中的索引路径

转载 作者:行者123 更新时间:2023-11-28 23:08:51 25 4
gpt4 key购买 nike

我正在尝试从我的地址簿中获取联系人。我在我的 tableview 上显示数据。首先,我设置了 tableviewcell 的高度。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

然后我实现

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

我在这些委托(delegate)方法中编写条件和逻辑。但是我面临一个问题,两种方法中索引路径的值都不同。因此,当我循环访问地址簿时(在这些方法中),两个委托(delegate)方法都以不同的顺序执行。为什么索引路径在两种情况下都有不同的值

最佳答案

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 仅在单元格进入 View 之前调用

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 在呈现 tableview 时为所有行调用以获得 tableview 内容的总高度。

而且我还必须同意@Vince 的评论,您唯一应该关心的是这些方法根据给定的索引路径返回正确的值。

通常你应该加载tableview 所需的所有数据,例如NSArray。然后根据索引路径从该数组中获取正确的对象。

关于iphone - 具有不同值的 TableView 委托(delegate)方法中的索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8744405/

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