發現一個奇怪的問題: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];
}
}