I have a UITableViewCell
which is linked to an object and I need to tell if the cell is visible. From the research I've done, this means I need to somehow access the UITableView
that contains it (from there, there are several ways to check if it's visible). So I'm wondering if UITableViewCell
has a pointer to the UITableView
, or if there was any other way to get a pointer from the cell?
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+
To avoid checking the iOS version, iteratively walk up the superviews from the cell's view until a UITableView is found:
Objective-C
id view = [cellInstance superview]; while (view && [view isKindOfClass:[UITableView class]] == NO) { view = [view superview]; } UITableView *tableView = (UITableView *)view;
Swift
var view = cellInstance.superview while (view != nil && (view as? UITableView) == nil) { view = view?.superview } if let tableView = view as? UITableView { tableView.beginUpdates() tableView.endUpdates() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With