我这样获取UITableViewCell中的UIButton:
-(void)buttonHandler:(UIButton *)button {
OrderCell *cell = [[button superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
这段代码在iOS 7之前版本中运行正常,但是在iOS 7上会出现以下错误:
[UITableViewCellScrollView item]: unrecognized selector sent to instance 0x17ae2cf0
如果您想在iOS 7上运行该应用程序,可以尝试如下操作:
-(void)buttonHandler:(UIButton *)button {
OrderCell *cell = [[[button superview] superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
那么它在iOS 7上可以工作,但之前的版本就不行?!?!
我通过以下方式规避了这个问题:
OrderCell *cell;
if([[[UIDevice currentDevice] systemVersion] isEqualToString:@"7.0"])
cell = [[[button superview] superview] superview];
else
cell = [[button superview] superview];
NSLog(@"cell.item = %@", cell.item.text);
但是到底发生了什么事情!?有人知道为什么会这样吗?
谢谢!