![](/img/trans.png)
[英]How to call a method in the viewController from a subclassed UIButton?
[英]Sending a Notification from a UIButton to a ViewController
我在故事板的外部 Nib 中创建了一个 UITableViewCell。 我已经设置了一个从 UITableViewController 到另一个 ViewController 的 segue,它在测试时运行良好。
我想知道如何让 Nib 中的 UIButton 调用[performSegueWithIdentifier:@"identifier" sender:self];
当它被按下时。
有任何想法吗? 我仍然很业余,所以如果你能解释清楚,我会很感激。
问候,
麦克风
在您的 ViewController.h 中执行以下操作:
- (IBAction)buttonPressed:(id)sender;
在您的 .m 文件中执行以下操作:
- (IBAction)buttonPressed:(id)sender {
[self performSegueWithIdentifier:@"identifier" sender:self];
}
现在转到您的.xib
文件并将按钮选择器连接到您的控制器。
你也可以在故事板上完成同样的事情; 右键单击按钮并将箭头拖动到您要导航到的视图控制器,它将提供 segue 选项(推送、模态、自定义)并选择一个。
在您的呼叫 VC 中处理它
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"identifier"]) {
>yoursecondVC> *secondViewController = [segue destinationViewController];
secondViewController.<param> = <param>;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.