0

我学习了ObjC程序流程,到目前为止我了解链从main.m->UIApplicationMain->AppDelegate->ViewController开始

我不明白的一点是 AppDelegate 类将焦点转移到 ViewController 中的哪个方法......

我觉得理解这个话题很重要,所以感谢任何澄清。

我有这个 Appdelegate.m 代码-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

MasterViewController *masterViewController = [[MasterViewController alloc] init];
self.navigationController = [[UINavigationController alloc] initWithRootViewController: masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;

在 ViewController 内部有这些方法 -

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
 [self.navigationController setNavigationBarHidden:YES animated: NO];
 }

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear: animated];
}

和其他方法...

我的问题是

  1. AppDelegate 在 MasterViewController 中将控制权转移到什么方法。在 MasterViewController “完成”它的工作或者它只是循环之后,控件会回来吗?
  2. MasterViewController 如何获取用于初始化的 xib 名称(它与 m 文件同名吗?即它是什么意思 - nibNameOrNil bundle:nibBundleOrNil)
  3. 我看到了导航控制器的参与,但是我不明白它是如何连接到视图控制器的......

如果你发现我的误解点-请耐心解释...我觉得过了这点我就可以开始了...

4

1 回答 1

0

(1) You're thinking about the logical flow in a procedural sort of way. The main run loop dispatches events down the responder chain. Your MasterViewController doesn't really 'finish'.

(2) The designated initializer for UIViewController is initWithNibName:bundle:. Your use of init here will not touch any associated nib file. If you wish to initialize MasterViewController from the nib, then you must use the designated initializer, e.g.

MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"your-nib-name-goes-here" bundle:nil];

nibNameOrNil and nibBundleOrNil are just parameter names for the method. It's a tip to you that they may be nil. Take a look at the documentation for how the method behaves when those params are nil.

(3) UINavigationController is a subclass of UIViewController that presents content hierarchically. In this case, the application's window's root view controller is a navigation controller. In turn, that navigation controller's root view controller is your MasterViewController instance.

The documentation for UINavigationController describes it well.

于 2013-08-25T12:35:07.487 回答