开发者

Switching from one view to second view?

I want to know that can in switch between two views in an iPhone application if I have chosen the application as window based application in the Xcode or it is开发者_Python百科 only possible to switch between views in view based application only.

How to design interface for changing the views in such appliocations as I am not able to design the second view in the interface builder after designing the first view.


Your view controller can present any other view controller like this

[firstViewController presentModalViewController:secondViewController animated:YES];

This will take you to second view controller.

To come back to first view controller, in second view controller you say

[secondViewController.parentViewController dismissModalViewControllerAnimated:YES];

Please refer to the documentation here


The main problem i think you have here is the perception of what each project type does.

A Window based application provides just a window and no "default" view controller for you to use.

A View based application provides a window AND a view controller and xib file for you to create your UI.

If you want to see how to add a view to a window based application create an empty view based application and look at the code that is auto added to the didFinishLaunchingWithOptions method in the appdelegate. This is essentially what you need to do with your window based application.

Add a view controller with a xib file for user interface, then look at how the view based application loads this view and displays it (using initWithNibName and then adding the view to the window)

i'd say you need to do more reading: take a look at cocoa fundamentals for iOS - in the documentation and then the view controller programming guide) these are both essential areas of reading. Then have a root around in the standard project types and take a look at how they are set up, this is really useful because you'll see what apple intend you to do when setting up your app


When you have your class which controls the UIWindow, you add objects in that window. One or some of these objects are Navigation Controllers or Views. in you windowController.h, you should define a view:

@property (nonatomic, retain) IBOutlet UIView *mainView;

and in the .m-file, synthesize it:

@synthesize mainView;

Then use it:

MainView *mainView = [[MainView alloc] initWithNibName:nil bundle:nil];
mainView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:mainView animated:YES];
[mainView release];

That is one of the two things that could possibly be your question. Another question you could ask is: how to switch from my window-based application to a view-based application?

You can just create new classes with corresponding .xib-files, being UIView's. Adapt your appDelegate classes and you should be fine.


Switching from one view to other in view based application

FirstViewController *firstViewController = [[UIViewController alloc] initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:firstViewController.view];

or you can also use this.

FirstViewController *firstViewController = [[UIViewController alloc] initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:firstViewController animated:YES]; // this is deprecated in ios6.0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜