访问UITableViewCell UIButton,自定义类

时间:2014-07-10 04:16:20

标签: ios objective-c uitableview nsindexpath

当我按下UItableViewCell中的按钮时,目标操作被触发,我需要在同一个单元格中的另一个按钮中显示图像。我的代码如下,但由于我的自定义UITableViewCell类,它给了我一个错误。有办法解决这个问题吗?

错误是:

incompatible pointer types, initializing CUSTOM_CELL with an expression of type UITableViewCell

我的CUSTOM_CELL属于:UItableViewCell

NSIndexPath *path = [[NSIndexPath alloc] initWithIndex:[sender tag]];
CUSTOM_CELL *cell = [self.TABLE cellForRowAtIndexPath:path];

[cell.BUTTON setImage:IMG_check forState:UIControlStateNormal];

UITableView CellForRowAtIndexPath

        //inits
        CUSTOM_CELL *cell = (CUSTOM_CELL *)
        [tableView dequeueReusableCellWithIdentifier:@"cell_item"];

        if (cell == nil){
            cell = [[CUSTOM_CELL alloc]initWithStyle:UITableViewCellStyleDefault
                                          reuseIdentifier:@"cell_item"];}

        //init the add button
        //*************************************************************


        [cell.BUTTON addTarget:self
                               action:@selector(SelectorMethod:)
                     forControlEvents:UIControlEventTouchUpInside];

2 个答案:

答案 0 :(得分:0)

问题很可能是您使用NSIndexPath

假设您的按钮的tag是它所在的行号而您只有一个部分,请尝试以下操作:

NSIndexPath *path = [NSIndexPath indexPathForRow:[sender tag] inSection:0];

答案 1 :(得分:0)

通过投射和校正分配准确的索引路径来解决问题

CUSTOM_CELL *cell = (CUSTOM_CELL*)[self.TABLE cellForRowAtIndexPath:indexPath];