您的位置:首页 > 产品设计 > UI/UE

How to get UITableView from UITableViewCell?

2014-11-03 18:25 417 查看
参考自:http://stackoverflow.com/questions/15711645/how-to-get-uitableview-from-uitableviewcell

通过UITableViewCell得到其UITableView

id view = [tableViewCellInstance superview];

while (view && [view isKindOfClass:[UITableView class]] == NO) {
view = [view superview];
}

UITableView *tableView = (UITableView *)view;

通过UITableViewCell上的子View来获得其对应的UITableViewCell

参考自:http://stackoverflow.com/questions/18962771/getting-uitableviewcell-with-superview-in-ios-7

UITableViewCell *cell = [button findSuperViewWithClass:[UITableViewCell class]]
@interface UIView (SuperView)

- (UIView *)findSuperViewWithClass:(Class)superViewClass;

@end

@implementation UIView (SuperView)

- (UIView *)findSuperViewWithClass:(Class)superViewClass {

UIView *superView = self.superview;
UIView *foundSuperView = nil;

while (nil != superView && nil == foundSuperView) {
if ([superView isKindOfClass:superViewClass]) {
foundSuperView = superView;
} else {
superView = superView.superview;
}
}
return foundSuperView;
}
@end


或者
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
UITableViewCell *cell = (UITableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: