我已经将UITableViewCell子类化为创建自定义单元格。在ViewController上,我添加了一个UITableView和一个原型单元格。我的自定义单元格出现并正常工作。
但是在我的didSelectRowAtIndexPath和didDeselectRowAtIndexPath方法中出现了一个警告,我无法摆脱。
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
MVGoalTVCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = cell.txtBox.text;
LogInfo(@"DESELECTED: %@", cellText);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
MVGoalTVCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = cell.txtBox.text;
LogInfo(@"SELECTED: %@", cellText);
}
警告显示在该行:
MVGoalTVCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
我在MVGoalTVCell中引用我的自定义单元格。
出现的警告如下:
使用“UITableViewCell *”类型的表达式初始化“MVGoalTVCell *”的指针类型不兼容
如何修复此警告?
答案 0 :(得分:9)
使用类型转换来修复警告。
MVGoalTVCell *cell = (MVGoalTVCell *)[self.tableView cellForRowAtIndexPath:indexPath];