- (void)viewDidLoad
{
FirstViewController *firstViewController = [[FirstViewController alloc]init];
SecondViewController *secondViewController = [[SecondViewController alloc]init];
ThirdViewController *thirdViewController = [[ThirdViewController alloc]init];
FourthViewController *fourthViewController = [[FourthViewController alloc]init];
FifthViewController *fifthViewController = [[FifthViewController alloc]init];
firstViewController.delegate = self;
secondViewController.delegate = self;
thirdViewController.delegate = self;
fourthViewController.delegate = self;
fifthViewController.delegate = self;
NSArray *viewControllerArray = [NSArray arrayWithObjects:firstViewController,secondViewController,thirdViewController,fourthViewController,fifthViewController,nil];
self.viewControllers = viewControllerArray;
[self.view setFrame:CGRectMake(0, 0, 320, 460)];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//每次当navigation中的界面切换,设为空。本次赋值只在程序初始化时执行一次
static UIViewController *lastController = nil;
//若上个view不为空
if (lastController != nil)
{
//若该实例实现了viewWillDisappear方法,则调用
if ([lastController respondsToSelector:@selector(viewWillDisappear:)])
{
[lastController viewWillDisappear:animated];
}
}
//将当前要显示的view设置为lastController,在下次view切换调用本方法时,会执行viewWillDisappear
lastController = viewController;
[viewController viewWillAppear:animated];
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;