亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

iOS應(yīng)用開(kāi)發(fā)中實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的簡(jiǎn)單方法筆記

 更新時(shí)間:2016年02月02日 09:12:11   作者:vane_  
這篇文章主要介紹了iOS應(yīng)用開(kāi)發(fā)中實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)的簡(jiǎn)單方法筆記,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下

作為新手寫的筆記,方便自己記憶:

從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

復(fù)制代碼 代碼如下:

@property (strong, nonatomic) UIViewController *viewController;
@property (strong, nonatomic) UINavigationController *navController;

delegate.m代碼didFinishLaunchingWithOptions函數(shù)中寫代碼:

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)代碼:
復(fù)制代碼 代碼如下:

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ì)象

復(fù)制代碼 代碼如下:

SubViewController *subView = [[SubViewController alloc] initWithNibName:@"SubViewController" bundle:[NSBundle mainBundle]];
    [self presentModalViewController:subView animated:YES];

這樣就好了。

iOS6.0之后都不用這個(gè)函數(shù)了

復(fù)制代碼 代碼如下:

[self presentModalViewController:subView animated:YES];

可以換成
復(fù)制代碼 代碼如下:

[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 聲明成員變量

復(fù)制代碼 代碼如下:

@property (strong, nonatomic) User *user;

2. view1

復(fù)制代碼 代碼如下:

View2 *view2 = [[View2  alloc] init];
    User *user = [[User alloc] init];
    user.name = @"kevin";
    view2.user = user;
    [self.navigationController pushViewController: view2
animated:YES];

3. view2

取到變量

復(fù)制代碼 代碼如下:

self.user.name

相關(guān)文章

最新評(píng)論