【问题标题】:didSelectRowAtIndexPath With Custom CelldidSelectRowAtIndexPath 与自定义单元格
【发布时间】:2013-12-18 19:30:16
【问题描述】:

我已将 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 *”的不兼容指针类型

如何解决此警告?

【问题讨论】:

    标签: uitableview ios7 didselectrowatindexpath


    【解决方案1】:

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

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

    【讨论】:

    • 修复了它。谢谢@hv88。
    猜你喜欢
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 2014-11-30
    相关资源
    最近更新 更多