发现一个奇怪的问题:php
手机(ios7)ios
2015-06-17 15:11:29.323 ***[1412:60b] [btn superview] = UITableViewCellContentView 数组
2015-06-17 15:11:29.324 ***[1412:60b] [[[btn superview]superview]class] = UITableViewCellScrollViewspa
模拟器:ios83d
2015-06-17 15:12:54.614 MyQ[7862:125756] [btn superview] = UITableViewCellContentView blog
2015-06-17 15:12:54.614 MyQ[7862:125756] [[[btn superview]superview]class] = EditTableViewCellit
百度了一下发现:io
http://www.cocoachina.com/bbs/read.php?tid=232335event
提供的方法:table
OffLineTableViewCell *cell = nil; if (IsIOS7) { UIView *view = [btn superview]; UIView *view2; if (IsIOS8) { view2 = view; }else{ view2 = [view superview]; } cell = (OffLineTableViewCell *)[view2 superview]; }else{ cell = (OffLineTableViewCell *)[btn superview]; }
果真太麻烦,弃用,换成如今这个,亲测可用。。。
这个方法真的是太靠谱了,这样还省了我要在TableViewCell中定义delegate。太赞!
还有一个支持这个方法的缘由:若是删除tableviewcell中的某个数据后,再点btn可能会出现数组越界的状况。
-(void)cellBtnClicked:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:favTableView];
NSIndexPath *indexPath =[favTableView indexPathForRowAtPoint:currentTouchPosition];
if (indexPath!=nil) {
ProfileViewController *profile = [[ProfileViewController alloc]init];
profile.empInfo = empSearchResultArray[indexPath.row]; //error
[self.navigationController pushViewController:profile animated:YES];
RootViewController *rootVC = (RootViewController *) self.tabBarController;
[rootVC showTabBar:NO];
}
}