切換View會用到的函數

切換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).屬性名

其中括號和類名是一種強制轉類型的用法。


17年資歷女工程師,專精於動畫、影像辨識以及即時串流程式開發。經常組織活動,邀請優秀的女性分享她們的技術專長,並在眾多場合分享自己的技術知識,也活躍於非營利組織,辦理活動來支持特殊兒及其家庭。期待用技術改變世界。