didSelectRowAtIndexPath With Custom Cell

mot*_*ion 1 uitableview didselectrowatindexpath ios7

我已经将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);

}
Run Code Online (Sandbox Code Playgroud)

警告显示在行上:

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

我在MVGoalTVCell中引用我的自定义单元格.

出现的警告如下:

不兼容的指针类型使用"UITableViewCell*"类型的表达式初始化"MVGoalTVCell*"

我该如何修复此警告?

小智 9

使用类型转换来修复警告.

MVGoalTVCell *cell = (MVGoalTVCell *)[self.tableView cellForRowAtIndexPath:indexPath];