Drew Drew - 1 year ago 72
iOS Question

Cannot access property in tableviewcell

I have some custom tableviewcells, each with a thumbnail having a gesture recognizer on it, to open a modal box.

In each tableviewcell there's a property containing a string.

In the method called by the gesture recognizer, i'm trying to access this property, by looping the superviews of the gesture recognizer.

- (void)handleLongPress:(UILongPressGestureRecognizer *)LongPressGestureRecognizer
//handle press
ZoomImageViewController *zoomImage = [self.storyboard instantiateViewControllerWithIdentifier:@"zoomImage"];

UIView *subview = LongPressGestureRecognizer.view;
while (![subview isKindOfClass:[UITableViewCell self]] && subview) {
subview = subview.superview;

UITableViewCell *cell = (UITableViewCell *)subview;

zoomImage.filename = cell.machinePicture;
zoomImage.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:zoomImage animated:YES completion:nil];


In debugger the cell object is the tableviewcellcontroller containing the property i want to access.
However, on the following line i get the error "Property 'machinePicture' not found on object of type 'UITableViewCell *'"

zoomImage.filename = cell.machinePicture;

I don't get why the property cannot by found, while cell seems to be the correct object i'm looking for, containing the property i want...

Answer Source

The standard UITableViewCell does not contain a machinePicture property, did you extend the UITableViewCell class?

Use that custom class instead, casting accordingly:

MyUITableViewCell *cell = (MyUITableViewCell *)subview;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download