我在我的MainWindow.xib中有一个UIButtonUIButton点击交换到另一个xib
当我点击按钮时,我想交换视图。我怎么做?
我也想转移的意见(如颜色偏好和一个字符串)
任何示例代码或链接到哪里可以找到我的答案之间的一些数据将是非常有益的。
我在我的MainWindow.xib中有一个UIButtonUIButton点击交换到另一个xib
当我点击按钮时,我想交换视图。我怎么做?
我也想转移的意见(如颜色偏好和一个字符串)
任何示例代码或链接到哪里可以找到我的答案之间的一些数据将是非常有益的。
alloc
一个临时视图控制器,并且调用initWithNibName:
。然后致电[self presentModalViewController:(the view controller you just made) animated:YES];
(或NO)。要传递数据,请在您的其他视图控制器上创建一个方法,将其添加到.h文件,然后在第一个视图控制器的.m文件中,将其导入并创建一个类,并调用[theviewcontrollermadeearlier yourmethod:argument :argument etc.];
例如:
MyFirstViewController.h:
#import <UIKit/UIKit.h>
#import "MySecondViewController.h"
...
@class MySecondViewController
...
MyFirstViewController.m:
...
MySecondViewController *tempVC = [[MySecondViewController alloc] initWithNibName:@"MySecondView"];
[self presentModalViewController:tempVC animated:YES];
[tempVC passDataWithString:@"a string" andColor:yellowcolor];
MySecondViewController.h:
@interface MySecondViewController : UIViewController {
...
}
- (void)passDataWithString:(NSString *)passedString andColor:(UIColor *)passedColor;
MySecondViewController.m:
...
- (void)passDataWithString:(NSString *)passedString andColor:(UIColor *)passedColor {
// Do something
}
编辑: 为了使按键触发此,在你的第一个视图控制器的头文件,在@interface
部分添加IBOutlet IBAction *buttonPressed;
,然后}
和@end
之间添加- (IBAction)buttonPressed;
围棋到Interface Builder中,并将IBAction
连接到该按钮。
然后,在你的第一个视图控制器的主文件中加上:
- (IBAction)buttonPressed {
// The code to execute when pressed
}