不兼容的指针类型警告

Phe*_*ter 2 types objective-c variable-assignment compiler-warnings

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

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

不兼容的指针类型使用UITableViewCell类型的表达式初始化SiteCell __strong

-(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;
    }
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释如何摆脱这种警告?

Hot*_*cks 15

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

SiteCell *cell = (SiteCell*)[tableView cellForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)