桨组词,exo_l,懒人谷
作为新手写的笔记,方便自己记忆:
从android转过来ios的,对于页面的跳转,找了很多资料,现在记录一下页面跳转的方法。
1.用navigationcontroller
2.直接跳(刚刚在网上找到的,不太熟,有错莫怪)
1.建一个rootviewcontroller,在delegate.h
@property (strong, nonatomic) uiviewcontroller *viewcontroller;
@property (strong, nonatomic) uinavigationcontroller *navcontroller;
delegate.m代码didfinishlaunchingwithoptions函数中写代码:
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];
这些代码加载第一个页面rootviewcontroller。
跳转到其他页面(比如subviewcontroller)代码:
subviewcontroller *subview = [[subviewcontroller alloc] init];
[self.navigationcontroller pushviewcontroller:subview animated:yes];
subview.title = @"sub";
这样的好处是会自动生成返回按钮。
2.直接跳转,什么都没有
不用做其他多余的,直接新建一个view对象
subviewcontroller *subview = [[subviewcontroller alloc] initwithnibname:@"subviewcontroller" bundle:[nsbundle mainbundle]];
[self presentmodalviewcontroller:subview animated:yes];
这样就好了。
ios6.0之后都不用这个函数了
[self presentmodalviewcontroller:subview animated:yes];
可以换成
[self presentviewcontroller:subview animated:yes completion:nil];
页面跳转时数据的传递
比如在需要实现view1跳到view2的时候,把view1的一些数据传给view2
思路:
1.自定义一个bean类user,在view2实现user为一个成员变量。
2.view1跳的时候把数据封装为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
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
-
iOS实现图片自动切换效果
本文实例为大家分享了ios实现图片自动切换的具体代码,供大家参考,具体内容如下#import "viewcontroller.h"#define imagevi...
[阅读全文]
-
-
-
-
-
-
-
网友评论