UIViewController的一些使用总结

最近学到UIViewControlller这个类,很显然,它在MVC编程模式中扮演的是控制器的角色,它有几个重要的方法。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;

- (void)loadView;

- (void)viewWillUnload

- (void)viewDidUnload


- (void)viewDidLoad;

- (void)viewWillAppear:(BOOL)animated;   // Called when the view is about to made visible. Default does nothing

- (void)viewDidAppear:(BOOL)animated;    // Called when the view has been fully transitioned onto the screen. Default does nothing

- (void)viewWillDisappear:(BOOL)animated;// Called when the view is dismissed, covered or otherwise hidden. Default does nothing

- (void)viewDidDisappear:(BOOL)animated; // Called after the view was dismissed, covered or otherwise hidden. Default does nothing

等等吧,相信这其中的调用流程,也该知道了,今天我想总结的是在两个,UIViewController之间来回跳转的时候,他的生命周期是怎么样的,以及一些调用流程。

这里我使用的是UINavigationController 这是一个导航栏,可以方便地在多个控制器之间来回跳转。

这是第一个控制器,名字为FirstViewController 

UIViewController的一些使用总结_第1张图片


这是加载这个控制器的时候,方法的调用顺序,现在我们点击书籍,会跳转到下一个页面。





UIViewController的一些使用总结_第2张图片


UIViewController的一些使用总结_第3张图片


在第一个控制器中单击书籍的处理事件:

- (void) bnClicked_in:(id) sender{

    NSLog(@"function %s line=%d",__FUNCTION__,__LINE__);

    

//会调用init方法

 SecondViewController *second=[[SecondViewControlleralloc] init];

//把下一个页面推入栈顶,会调用loadView方法

[self.navigationControllerpushViewController:second animated:YES];

    

    NSLog(@"pushViewController之后");

    [second release];

    

    NSLog(@"把创建的secondrelease");

}

从上面的截图中很容易看出


你可能感兴趣的:(编程,mvc,function)