ios - 如何在 iOS 应用程序中加载初始 UIViewController?

标签 ios iphone objective-c uiviewcontroller

我是 iOS 开发的新手,我知道我遗漏了一些简单的东西,但我不确定它是什么......我有一个简单的“Hello World”应用程序,我正在尝试获取我的要加载的初始 View Controller 。

采取的步骤:

  1. 我创建了一个空项目
  2. 我添加了一个扩展 UIViewController 的自定义 View Controller 类:


#import "WebViewController.h"

@interface WebViewController ()
@end

@implementation WebViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
@end
  1. 我使用 Apple 的向导添加了 Storyboard。
  2. 我向该 Storyboard添加了一个 View Controller 。
  3. 我将自定义 Controller 设置为该 View Controller 的“自定义类”。
  4. 我选中了“是初始 View Controller ”复选框。 storyboard

但是当我运行该应用程序时,我的 Controller 不会加载(从未调用过 viewDidLoad)。我错过了什么?

抱歉这个菜鸟问题...

最佳答案

enter image description here

放大图像。在显示“主界面”的地方,从该菜单中选择要启动的 Storyboard。在您的 Storyboard出现在列表中之前,您可以稍微摇动 Xcode。如果它现在出现了,请尝试保存 Storyboard 文件以及清理/构建项目等操作。图片借自 raywenderlich.com .


在您的 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { 方法中,在您的应用程序委托(delegate) .m 文件中:

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:
    @"MainStoryboard" bundle:nil];
UIViewController *initViewController = [storyBoard 
    instantiateInitialViewController];
[self.window setRootViewController:initViewController];

关于ios - 如何在 iOS 应用程序中加载初始 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21247188/

相关文章:

ios - 从动态表格单元格链接到特定的 View Controller

ios - 有什么方法可以从自定义 UITableViewCell 类更改 UITableView 高度?

iPhone 应用程序 : Questions on interaction between CLLocationmanager and MKMapView (showing current user location)

iphone - 基于图像的核心图形绘制

iphone - 如何以编程方式安装 iOS 应用程序?

iphone - 反转声波的算法

ios - 两行首字母非常大的 UILabel 或 UITextView

ios - Xcode 8.3.2 Clang 错误

iphone - 应用程序加载程序警告 : The app references non-public selectors in Payload/<Appname>. app/<App name>: changeState:

objective-c - 从自定义 UITableViewCell 调用 UITableViewController 中的方法