iphone - 将 UIViewController 传递给另一个 ViewController 中的另一个 Button

标签 iphone ios xcode

我有三个这样的按钮,每个按钮对应一个不同的UIViewController:

enter image description here

例如,我按下按钮 1。它会将与要显示的数字相对应的 View Controller 传递给开始按钮。

我需要能够在此按钮中传递它:

enter image description here

这可能吗?

最佳答案

是的,只需在按钮点击时显示的 View Controller 上创建 UIButton 作为属性即可。然后,在按钮点击的处理程序中,在显示新 Controller 之前使用新 Controller 上的按钮属性来分配按钮。

示例代码:

//here's your method invoked when pressing the button 1
- (IBAction) pressedButtonOne:(id) sender {
    NewViewController *newVc = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
    newVc.startButton = self.startButton;
}

这是按下按钮 1 时在 Controller 中创建的代码

NewViewController.h

#import <UIKit/UIKit.h>
@interface NewViewController : UIViewController
@property (nonatomic, retain) UIButton *startButton;

//NewViewController.m
- (void) viewDidLoad {
    //use self.startButton here, for whatever you need
}

关于iphone - 将 UIViewController 传递给另一个 ViewController 中的另一个 Button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10808925/

相关文章:

iphone - NSString 到 int 问题

iphone - 我们可以从iPhone App中的AppStore访问App信息吗

objective-c - NSRegularExpression 字符串由

启动时Xcode错误

ios - 如何在 Apple-Watch 上获取 iPhone 日历事件提醒

ios - 是否可以向 HealthKit 添加自定义数据?

ios - Visual Studio 2015 Xamarin 表单可移植项目部署到 iPad 失败

ios - UIProgressView 设置进度

ios - 由于应用程序中超过自动锁定时间,如何检测手机已被锁定?

ios - 将 PinTintColor 调整为 mapkit 的 Ray Wenderlich 教程