gpt4 book ai didi

objective-c - 不兼容的指针类型警告(在 Objective-C 中)

转载 作者:行者123 更新时间:2023-12-04 02:47:00 24 4
gpt4 key购买 nike

我在 iOS 开发中仍然有点绿色,并且不断收到我不确定的警告。

我在 tableview 中使用自定义单元格,并将其类设置为 UITableViewCell 的子类,称为 SiteCell。在我的“didSelectRowAtIndexPath”方法中,当我将所选单元格声明为 SiteCell 类型时,我收到以下警告:

Incompatible pointer types initializing SiteCell __strong with an expression of type UITableViewCell


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

NSString *rowIdentity = [NSString stringWithFormat:@"%d", indexPath.row];
[selectedRows setObject:[cell.siteTitleLabel text] forKey:rowIdentity];

if(cell.accessoryType == UITableViewCellAccessoryCheckmark){
cell.accessoryType = UITableViewCellAccessoryNone;
}else{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}

任何人都可以说明如何摆脱这个警告吗?

最佳答案

假设 cellForRowAtIndexPath 被正确编码,并且已知总是返回 SiteCell ,你只需要转换到 SiteCell* :

SiteCell *cell = (SiteCell*)[tableView cellForRowAtIndexPath:indexPath];

关于objective-c - 不兼容的指针类型警告(在 Objective-C 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15818675/

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