How to switch between Views on iOS

2019-08-10 22:28发布

i am pretty new to the iOS world and since I'm coming from the Activity-based world of Android I'm a little bit confused with how iOS manages transitions between Views.

I already created a UIViewController which displays a Login form in full screen (It's an app targeted for the iPad). After a successful login I want to switch to another View and utilize a UISplitViewController. To be able to push from my initial controller to the second (which is also a UIViewController) I've already added an UINavigationController with my first controller being the root.

I've added the UISplitViewController to the xib of my second UIViewController. Xcode previously complained that my second UIViewController didn't have the view outlet set, so I basically blindly set that to the detailView within my UISplitViewController.

The result is that the first UIViewController gets indeed pushed away but I don't get the UISplitViewController to show up but the DetailView I have set in the view outlet.

Did I miss something? What is necessary to first display a full screen (nothing fancy, no frills) UISplitViewController and then push over to UISplitViewController? My previous attempts involed the new Storyboard feature but that turned out to be even more confusing (ie. too much magic involved). Maybe I just got some of the UI paradigms of iOS wrong.

3条回答
相关推荐>>
2楼-- · 2019-08-10 23:03

Generally speaking, you want to set UIViewController's view outlet to the top level view in your xib. When you created the xib, it probably gave you a blank view as the starting point, which you then added your UISplitView to. That (formerly) blank view is the one you want as the view outlet.

查看更多
我命由我不由天
3楼-- · 2019-08-10 23:07

In the given code . I am switching to next View on button click..

NextController (View you want to display like a new Activity we display in Android )

First of all import it lik

#import "NextController.h"

and then

- (IBAction)clicking:(id)sender {

    NextController *nextviewcontroller = [[NextController alloc]initWithNibName:@"NextController" bundle:nil];// include it before calling it..

    [self presentViewController:nextviewcontroller animated:YES completion:nil];

}

where initWithNibName:@NameOfNibFileToShow and presentViewController is built in function and animated:YES to show animation

查看更多
Emotional °昔
4楼-- · 2019-08-10 23:10

You probably want to start with a UINavigationController as your root view controller. UINavigationController's init method takes another view controller as a parameter (confusingly also called a root ViewController) which can be the view controller that you are currently using as the root view controller for your application. That will then be displayed within the navigation controller.

Once you've put your view controller inside a navigation controller, you can call [self.navigationController pushViewController:x] to display a new view controller, and [self.navigationController popViewController] to go back again. If you don't want the navigation bar at the top, you can set it to hidden.

Alternatively, you can display a full-screen view controller from within another view controller by calling [self presentModalViewController:x] to show it.

查看更多
登录 后发表回答