我是iOS编程的新手。 到目前为止我只在Android上编程,而Objective-C现在对我来说是一种完全不同的新语言。
我想要做的是不要使用我用故事板创建的设计。 我想以编程方式完成所有操作,因为我认为如果我这样做会更有动态。
我遇到的问题是,我希望有3种不同的观点。 我google了一下,偶然发现了一些stackoverflow问题。 在那里,人们建议使用NavigationController 。 好的。 现在我正在尝试实现它。 我想要的是以下内容
一个MainViewController ,有3个不同的视图。 第一个视图是loginView。 第二个是显示数据,第三个是根据第二个视图的点击显示详细数据。
这是一个navigationcontroller corerct吗? 我遇到的问题是我告诉应用程序我想从MainViewController开始并在其中推送LoginView。
我有一个MainViewController.h和MainViewController.m ,它们是UIViewController子类
现在,我到底在哪里做到这一点? 我在这里有didFinishLaunchingWithOptions方法,其中包含以下内容
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; UIViewController *viewController = [[MainViewController alloc]init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; [navigationController pushViewController:viewController animated:NO]; self.window.rootViewController = navigationController; [self.window makeKeyAndVisible]; return YES; }但这只是崩溃的应用程序。 我究竟做错了什么? 我如何获得这三种观点? 我开始完全错了吗? 请帮忙。 正如我所说,我是iOS开发的新手。 我很容易在一个视图上编程。 我已经这样做了,但我想要不同的观点! 谢谢!
I'm totally new to iOS programming. I only programmed on Android so far and Objective-C is a total different and new language for me now.
What I want to do is to not use a design that I've created with the storyboard. I want to do all programmatically, since I think it will be more dynamic if I do it like this.
The problem I'm encountering is, that I want to have 3 different views. I googled a bit, and stumbled upon some stackoverflow questions. There, people suggested using a NavigationController. Okay. Now I'm trying to implement it. What I want to have is the following
A MainViewController that has 3 different views. The first view is a loginView. The second one is displaying data and the third is displaying detailed data dependent on the click of the second view.
Is a navigationcontroller corerct for this? The problem I'm having is where I tell the app that I want to start with the MainViewController and push the LoginView in it.
I have a MainViewController.h and MainViewController.m that are subclasses of UIViewController
Now, where exactly do I do this? I have the didFinishLaunchingWithOptions method right here with the following content
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; UIViewController *viewController = [[MainViewController alloc]init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; [navigationController pushViewController:viewController animated:NO]; self.window.rootViewController = navigationController; [self.window makeKeyAndVisible]; return YES; }But that just crashes the app. What am I doing wrong? How do I get those three views? Am I starting completely wrong? Please help. As I said I'm new to iOS development. It's easy for me to programm on one view. I did that already, but I want thre different views! Thanks!
最满意答案
一个MainViewController ,有3个不同的视图。 第一个视图是loginView。 第二个是显示数据,第三个是根据第二个视图的点击显示详细数据。
那是错的。
您需要三个不同的视图控制器,每个视图控制器将管理自己的视图。
然后在导航控制器中依次推送,具体取决于用户交互。
A MainViewController that has 3 different views. The first view is a loginView. The second one is displaying data and the third is displaying detailed data dependent on the click of the second view.
That's wrong.
You need three different view controllers, each of those will manage its own view.
Then you push one after another in the navigation controller, depending on user interaction.
更多推荐
发布评论