TableViewCell子视图无法在IOS 7中访问 [英] TableViewCell subviews can't access in IOS 7

查看:89
本文介绍了TableViewCell子视图无法在IOS 7中访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用自定义 TableViewCell 。它适用于IOS 6,但我在ios 7中出错。当我访问 UITableViewCell的子视图时出错

I am using a customized TableViewCell in my App. It works fine with IOS 6 but I got error in ios 7. Error occurred when I access sub views of UITableViewCell

请参阅下面的代码我遇到错误

see the code below where I got error

- (void)addButtonClicked:(UIButton *)button {

    Product *product = [productsArray objectAtIndex:button.tag];
    NSString *code = product.code;
    OTATableCell *cell = (OTATableCell *) [[button superview] superview];

    cell.priceLabel; // here i get error

}

显示的错误是:

-[UITableViewCellScrollView priceLabel]: unrecognized selector sent to instance 0x15d0ff80

请帮我解决这个问题。
提前致谢。

Please help me to solve this problem. Thanks in advance.

推荐答案

还需要一个 superView 致电:

 OTATableCell *cell = (OTATableCell *)[[[button superview] superview] superview];

您可以查看以下内容:

对于iOS> = 7:

For iOS >= 7:

       NSLog(@"%@",[[sender superview] class]);   //UITableViewCellContentView
       NSLog(@"%@",[[[sender superview] superview] class]); //UITableViewCellScrollView
       NSLog(@"%@",[[[[sender superview]superview]superview] class]);  //UITableViewCell

适用于iOS< 7:

For iOS < 7:

       NSLog(@"%@",[[sender superview] class]);   //UITableViewCellContentView
       NSLog(@"%@",[[[sender superview] superview] class]); //UITableViewCell
       NSLog(@"%@",[[[[sender superview]superview]superview] class]);  //UITableView

编辑:如果你不想依赖 superView 属性:

UIButton *button = (UIButton *)sender;
CGRect buttonFrame = [button convertRect:button.bounds toView:self.table];
NSIndexPath *indexPath = [self.table indexPathForRowAtPoint:buttonFrame.origin];

//使用 indexPath 访问单元格:

//Access the cell using indexPath:

UITableViewCell *cell=[self.table cellForRowAtIndexPath:indexPath];
   cell.label=@"setText";

这篇关于TableViewCell子视图无法在IOS 7中访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆