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
通过UITableViewCell上的子View来获得其对应的UITableViewCell
参考自:http://stackoverflow.com/questions/18962771/getting-uitableviewcell-with-superview-in-ios-7
UITableViewCell *cell = [button findSuperViewWithClass:[UITableViewCell class]]
或者
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
UITableViewCell *cell = (UITableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];
通过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];
相关文章推荐
- How to get UITableView from UITableViewCell?
- How to stop UITableView from clipping UITableViewCell contents in iOS 7
- USBView & How to get the Serial Number from a USB disk & qextserialport
- reason: 'UITableView failed to obtain a cell from its dataSource'
- How to get byte array from imageview
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- How to get DataKey, RowIndex or Row from a GridView row event
- How to popup a UIPickerView from the bottom of a UIScrollView in response to UITextField selection
- How to make UILabel / UITableViewCell to have a dynamic height
- How to get a notification from Linux when the set of network interfaces changes
- How to get bean from tag component
- From an inner class, "this" points to the inner object. How do I get a "this" pointer to the enclosing object?
- I'm on Facebook--Now What???: How to Get Personal, Business, and Professional Value from Facebook
- How to get file from classpath
- How to get tbl from TPCH?——数据库学习初探
- How to use gcov to get code coverage from static library in iphone?
- How to Display a SharePoint Dialog from Ribbon Button and Get Selected Item Context
- How to use GET and POST methods in HTTP from a MIDlet
- HOWTO get multiple value from the same name checkbox elements or radiobution elements
- how to get internal items from a dialog created from wizard of VC2005