gpt4 book ai didi

ios - 如何获取在 UITableView 中选择的单元格的类(自定义)?

转载 作者:可可西里 更新时间:2023-11-01 06:18:05 24 4
gpt4 key购买 nike

通常我通过这种方式获取我选择的单元格:

- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell*) [table cellForRowAtIndexPath:indexPath];
}

但在我使用的代码中,我的 TableView 中可能有多种单元格。如何获取所选单元格的类(例如,如果是 CustomCellCustomCell2)?

最佳答案

您可以检查返回的单元格类型

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell isKindOfClass:[CustomCell class]]) {
//do specific code
}else if([cell isKindOfClass:[CustomCell2 class]]){
//Another custom cell
}else{
//General cell
}

关于ios - 如何获取在 UITableView 中选择的单元格的类(自定义)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17010666/

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