iOS應(yīng)用開(kāi)發(fā)中實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的簡(jiǎn)單方法筆記
作為新手寫(xiě)的筆記,方便自己記憶:
從android轉(zhuǎn)過(guò)來(lái)iOS的,對(duì)于頁(yè)面的跳轉(zhuǎn),找了很多資料,現(xiàn)在記錄一下頁(yè)面跳轉(zhuǎn)的方法。
1.用navigationController
2.直接跳(剛剛在網(wǎng)上找到的,不太熟,有錯(cuò)莫怪)
1.建一個(gè)RootViewController,在delegate.h
@property (strong, nonatomic) UIViewController *viewController;
@property (strong, nonatomic) UINavigationController *navController;
delegate.m代碼didFinishLaunchingWithOptions函數(shù)中寫(xiě)代碼:
RootViewController *rootView = [[RootViewController alloc] init];
rootView.title = @"Root View";
self.navController = [[UINavigationController alloc] init];
[self.navController pushViewController:rootView animated:YES];
[self.window addSubview:self.navController.view];
這些代碼加載第一個(gè)頁(yè)面RootViewController。
跳轉(zhuǎn)到其他頁(yè)面(比如SubViewController)代碼:
SubViewController *subView = [[SubViewController alloc] init];
[self.navigationController pushViewController:subView animated:YES];
subView.title = @"Sub";
這樣的好處是會(huì)自動(dòng)生成返回按鈕。
2.直接跳轉(zhuǎn),什么都沒(méi)有
不用做其他多余的,直接新建一個(gè)view對(duì)象
SubViewController *subView = [[SubViewController alloc] initWithNibName:@"SubViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:subView animated:YES];
這樣就好了。
iOS6.0之后都不用這個(gè)函數(shù)了
[self presentModalViewController:subView animated:YES];
可以換成
[self presentViewController:subView animated:YES completion:nil];
頁(yè)面跳轉(zhuǎn)時(shí)數(shù)據(jù)的傳遞
比如在需要實(shí)現(xiàn)view1跳到view2的時(shí)候,把view1的一些數(shù)據(jù)傳給view2
思路:
1.自定義一個(gè)bean類user,在view2實(shí)現(xiàn)user為一個(gè)成員變量。
2.view1跳的時(shí)候把數(shù)據(jù)封裝為user, 并且賦值給view2.user
代碼
1. view2
.h 聲明成員變量
@property (strong, nonatomic) User *user;
2. view1
View2 *view2 = [[View2 alloc] init];
User *user = [[User alloc] init];
user.name = @"kevin";
view2.user = user;
[self.navigationController pushViewController: view2
animated:YES];
3. view2
取到變量
self.user.name
相關(guān)文章
iOS開(kāi)發(fā)一個(gè)好看的ActionSheet
本篇文章通過(guò)代碼分享和圖文形式教給大家用IOS寫(xiě)一個(gè)好看的ActionSheet過(guò)程以及注意事項(xiàng),需要的朋友參考下吧。2018-01-01
詳解IOS11新特性之larget title的實(shí)現(xiàn)
本篇文章主要介紹了詳解IOS11新特性之larget title的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-12-12
Objective-C 經(jīng)典字典數(shù)組排序 - 省市區(qū)
本文主要介紹Objective-C 字典數(shù)組排序,這里整理相關(guān)資料及實(shí)現(xiàn)示例代碼,有興趣的小伙伴可以參考下2016-09-09
iOS在固定的label上動(dòng)態(tài)顯示所有文字
這篇文章給大家主要介紹了iOS中如何實(shí)現(xiàn),在固定的label上動(dòng)態(tài)顯示所有文字的方法,文中給出了示例和思路,對(duì)大家的理解很有幫助,感興趣的朋友們下面來(lái)一起看看吧。2016-10-10
IOS實(shí)現(xiàn)視頻動(dòng)畫(huà)效果的啟動(dòng)圖
這篇文章實(shí)現(xiàn)的是一個(gè)關(guān)于啟動(dòng)頁(yè)或者引導(dǎo)頁(yè)的視頻動(dòng)畫(huà)效果的實(shí)現(xiàn)過(guò)程,對(duì)于大家開(kāi)發(fā)APP具有一定的參考借鑒價(jià)值,有需要的可以來(lái)看看。2016-09-09

