切換UIViewController的兩種方式
1. 有NavigationController時
方法一:右側進入
SecondViewController* svc=[[SecondViewController alloc]init]; [self.navigationController pushViewController:svc animated:YES];
返回到上一頁
[self.navigationController popViewControllerAnimated:YES];
方法二:下面切入
SecondViewController* svc=[[SecondViewController alloc]init]; [self.navigationController presentModalViewController:svc animated:YES];
返回到上一個UIViewController
[self.navigationController dismissModalViewControllerAnimated:YES];
2、没有NavigationController的切換方法
SecondViewController* svc=[[SecondViewController alloc]init]; [self presentModalViewController:svc animated:YES];
返回到上一個UIViewController
[self dismissModalViewControllerAnimated:YES];
取得子viewController或父ViewController的方式
假設View A是來源的ViewController,而View B是目標ViewController。
1.取得子viewController
((B *)self.presentedViewController).屬性名
2.取得父viewController
((A *)self.presentingViewController).屬性名
其中括號和類名是一種強制轉類型的用法。