简体   繁体   English

无法从UITableViewCell调用performSegueWithIdentifier

[英]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. 我已经通过情节提要声明了segue,并且试图从我编写的用于处理动态原型的自定义TableViewCell调用它。

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

I'm getting a No visible @interface for 'PhotoChoiceTableViewCell' declares the selector 'performSegueWithIdentifier:sender:' error. 我收到No visible @interface for 'PhotoChoiceTableViewCell' declares the selector 'performSegueWithIdentifier:sender:'No visible @interface for 'PhotoChoiceTableViewCell' declares the selector 'performSegueWithIdentifier:sender:'错误。

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. 我想我已经确定我需要从UIView调用segue,但是我不知道如何实现适当的委托或协议来执行此操作。

My UITableViewController is called InboxViewController and my UITableViewCell is called PhotoChoiceTableViewCell. 我的UITableViewController称为InboxViewController,我的UITableViewCell称为PhotoChoiceTableViewCell。

Thank you! 谢谢!

Call the performSegueWithIdentifier on your view controller. 在视图控制器上调用performSegueWithIdentifier The cell does not implement this method. 单元不实现此方法。

Step 1. Implement a protocol. 步骤1.实施协议。

@class MyCell;
@protocol MyDelegate <NSObject>

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

@end


@interface MyCell : UITableViewCell

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

@end

Step 2. 第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. 在配置单元格时,请记住将视图控制器设置为委托。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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