Each window in the five buttons, so easy to switch to other views
# Import
# Import "FirstViewController.h"
# Import "SecondViewController.h"
# Import "ThirdViewController.h"
# Import "FourViewController.h"
@ Interface ViewController: UIViewController
- (IBAction) gotoFirstView: (id) sender;
- (IBAction) gotoSceondView: (id) sender;
- (IBAction) gotoThirdView: (id) sender;
- (IBAction) gotoFourView: (id) sender;
@ Property (retain, nonatomic) FirstViewController * firstViewController;
@ Property (retain, nonatomic) SecondViewController * secondViewController;
@ Property (retain, nonatomic) ThirdViewController * thirdViewController;
@ Property (retain, nonatomic) FourViewController * fourViewController;
@ End
The above is the main View code
Click on each subsequent code below
BUTTON- (IBAction) gotoFirstView: (id) sender {
if (self.firstViewController == nil) {
firstViewController = [[FirstViewController alloc] initWithNibName: @ "FirstViewController" bundle: nil];
[Self.view addSubview: firstViewController.view];
} Else {
[Self.view addSubview: firstViewController.view] ;/ / re-display the first window
}
}
- (IBAction) gotoSceondView: (id) sender {
if (self.secondViewController == nil) {
secondViewController = [[SecondViewController alloc] initWithNibName: @ "SecondViewController" bundle: nil];
[Self.view addSubview: secondViewController.view];
}
}
- (IBAction) gotoThirdView: (id) sender {
if (self.thirdViewController == nil) {
thirdViewController = [[ThirdViewController alloc] initWithNibName: @ "ThirdViewController" bundle: nil];
[Self.view addSubview: thirdViewController.view];
}
}
- (IBAction) gotoFourView: (id) sender {
if (self.fourViewController == nil) {
fourViewController = [[FourViewController alloc] initWithNibName: @ "FourViewController" bundle: nil];
[Self.view addSubview: fourViewController.view];
}
}
In such a way that I can switch to another window
In FirstViewController to be cut back to the main window, I use the following code
- (Void) viewDidLoad
{
[Super viewDidLoad];
/ / Do any additional setup after loading the view from its nib.
NSLog (@ "FirstViewDisplay");
}
- (Void) viewWillAppear: (BOOL) animated {
NSLog (@ "FirstViewDisplay viewWillAppear");
}
- (Void) viewDidUnload
{
[Super viewDidUnload];
/ / Release any retained subviews of the main view.
/ / E.g. self.myOutlet = nil;
NSLog (@ "FirstViewRemove");
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
{
return YES;
}
- (IBAction) gotoMainView: (id) sender {/ / The first window to remove
[Self.view removeFromSuperview];
}
- (IBAction) gotoSecondView: (id) sender {
}
- (IBAction) gotoThirdView: (id) sender {
}
- (IBAction) gotoFourView: (id) sender {
}
So that I can achieve with the main FirstView with the main switch
ViewThe first switch to FirstViewController viewDidLoad function call about
Is there a way to switch to FirstViewController window every time there is news notice it
There is a switch back to the main View when there are message notification, because the main View of viewDiidLoad will only be called once, later switching would not call
Want to achieve these five VIEW button to switch between each other, and there is a message notification, the
ask you seniors
Reply:
NSNotification this can send a message, you can look at. Certainly can solve your problem.
But the view of the switch so you do not, and you may not understand the iphone's view, and the windows of the form is essentially different. Slowly learning it.
Reply:
Thank you for your answer, I have just started to engage in this thinking is still stuck in windows side, but the business needs are Well, you need to be able to see some form of mutual switch
Reply:
I have an example of left-mail sent to you, only to realize the switching view, there is no transfer news
Reply:
2570338224@qq.com
No comments:
Post a Comment