我有三个这样的按钮,每个按钮对应一个不同的UIViewController
:
例如,我按下按钮 1。它会将与要显示的数字相对应的 View Controller 传递给开始按钮。
我需要能够在此按钮中传递它:
这可能吗?
最佳答案
是的,只需在按钮点击时显示的 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/