开发者

Assign new UIViewController or a UIView directly?

From the standard view-based application, I found that the generated code did this:

self.window.rootViewController = self.viewController;

So I take it as such that the AppDelegate (self) has a local variable (declared property) named viewController, which is a subclass of UIViewController, and the self.window.rootViewController is pointed towards this view controller.

When a button is clicked on the screen, I would like to jump to a new view.

Now I have created a new subclass of UIViewController, say abcViewController, and a xib file which represents the view. Should I:

(1) replace "viewController" with "abcViewController" so that it becomes the new Application Delegate's window's new rootViewController

or

[self.view removeFromSuperview];
[self.parentViewController.view addSubview:abcViewController];

Do I add/remove the view directly, or should I swap the view controllers, then do something to change the view within that view controller? Do I also need a new subclass of UIViewController for开发者_C百科 every view that I would like to add to the App?


It depends on how you want it to work visually. Do you want the user to be able to go back to the original view from this new view? Then you should probably use UINavigationController as the window's root view controller. Besides the ability to go back to the original view, you will also get a nice animation effect by default -- making it more pleasing for your users than a simple swapping effect.

Almost every control that you see in your app is a subclass of UIView -- you don't need to create a view controller for all of them. What you typically do need a view controller for is for the base view of every new "screen". And usually yes, you would subclass UIViewController or UITableViewController for each of these views.


Do like this.

In viewController class on which event you want to switch the view at there use this,

-Make object of appDelegate class, -then on this object access the window . -Make object for new view -and add it on window.

see this,

    YourAppDelegate *obj=(YourAppDelegate *)[[UIApplication sharedApplication] delegate]; 

abcViewController *objAbc=[[[abcViewController alloc] initWithNibName:@"abcViewController" bundle:nil] autorelease];

    [obj.window addSubview:objAbc.view];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜