简体   繁体   中英

Cannot call performSegueWithIdentifier from a UITableViewCell

I am having trouble resolving this issue. I have declared a segue via the storyboard and I'm trying to call it from a custom TableViewCell I wrote to handle the dynamic prototype.

- (IBAction)clickedPhoto:(id)sender {
[self performSegueWithIdentifier:@"PhotoDetail" sender:self];
}

I'm getting a No visible @interface for 'PhotoChoiceTableViewCell' declares the selector 'performSegueWithIdentifier:sender:' error.

I think I've figured out that I need to call the segue from a UIView but I can't figure out how to implement the proper delegate or protocol to do this.

My UITableViewController is called InboxViewController and my UITableViewCell is called PhotoChoiceTableViewCell.

Thank you!

Call the performSegueWithIdentifier on your view controller. The cell does not implement this method.

Step 1. Implement a protocol.

@class MyCell;
@protocol MyDelegate <NSObject>

- (void)photoTappedInCell:(MyCell *)cell;

@end


@interface MyCell : UITableViewCell

@property (nonatomic, weak) id<TRUProductImageGalleryCellDelegate> delegate;

@end

Step 2.

Call a delegate in your cell:

- (IBAction)deleteButtonTapped:(id)sender
{
    if ([_delegate respondsToSelector:@selector(photoTappedInCell:)])
    {
        [_delegate performSelector:@selector(photoTappedInCell:) withObject:self];
    }
}

And remenber to set your view controller as a delegate when you're configuring the cell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM