简体   繁体   English

要制作哪种类型的ViewController?

[英]What Type of ViewController To Make?

I have a button that when pressed, brings up a modal view. 我有一个按钮,当按下该按钮时,会弹出一个模态视图。

Lets call this modal view "AboutViewController". 让我们将此模式视图称为“ AboutViewController”。

My question is, what type of viewController should this be. 我的问题是,这应该是哪种类型的viewController。 I set up the rest of my app a while ago and don't remember exactly how I got it setup. 我前一段时间设置了我的应用程序的其余部分,并且不记得确切地如何设置它。

I already have a TabBar that is present so Ill just make it viewable at the bottom, that shouldn't be an issue. 我已经有一个TabBar,所以我只能在底部使其可见,这不成问题。

But I want it to be a navController but I want it to be separate from the nav stack of the rest of my app, I will then add a UITable, etc in IB. 但是我希望它成为navController,但我希望它与我的其余应用程序的nav堆栈分开,然后在IB中添加UITable等。

Just do: 做就是了:

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:AboutViewController];
[self presentModalViewController:nav animated:YES]; 

I assume you have a class for the Modal View? 我假设您有一个模态视图类? Say you called it AboutViewController. 假设您将其称为AboutViewController。

You would just need to do: 您只需要执行以下操作:

    AboutViewController *viewController = [[AboutViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    [viewController release];

    [self presentModalViewController:navController animated:YES];
    [navController release];

The nav stack for the Modal View will be separate from your other nav stack and your Modal View Controller will handle it. 模态视图的导航堆栈将与其他导航堆栈分开,并且模态视图控制器将对其进行处理。

You can add that view as a PresentModalViewController. 您可以将该视图添加为PresentModalViewController。 You have to add that view as same as we are adding the other view in our project. 您必须像在项目中添加其他视图一样添加该视图。

And then after when button is pressed you have to write below code to show that view. 然后在按下按钮后,您必须编写以下代码来显示该视图。

AboutViewController *aboutViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil];
[self presentModalViewController:aboutViewController animated:YES];
[aboutViewController release];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM