gpt4 book ai didi

iphone - 以编程方式添加 UITableView - 如何设置单元格的重用标识符?

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

我有一个 UIViewController,它在某个时候会生成一个 UITableView,当它生成时,我只需初始化 TableView 实例变量并将其添加到 View 中,但我不确定如何处理单元格的出队以添加到看法;我需要一个重用标识符,但我不确定如何设置它。

我在这个方法中做什么?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"wot";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

return cell;
}

最佳答案

使用方法initWithStyle:reuseIdentifier

  1. 检查cell是否存在
  2. 如果没有,则需要对其进行初始化。

代码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath*)indexPath 
{
static NSString *cellIdentifier = @"wot";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

if (!cell)
cell = [[UITableViewCell alloc] initWithStyle: someStyle reuseIdentifier: cellIdentifier];

return cell;
}

关于iphone - 以编程方式添加 UITableView - 如何设置单元格的重用标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15772311/

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