【通讯录案例-顺传用户名 Objective-C语言】
发布时间:2024年01月15日
一、我们说那个“顺传”啊,大家应该能明白是什么意思

1.首先,“顺传”呢,需要,
1)第一,在B控制器的“点儿”h文件里边儿,声明对应的类型,
2)第二,直接拿到B的对象,赋值
2.好,然后,接下来呢,我们现在呢,

我们是想把A控制器的用户名,传给B控制器,

现在啊,当我们点击“登录”按钮的时候,一定是可以拿到这个用户名的,这个“1”,这个肯定是可以的,上边儿的内容,肯定可以拿的到,
command + R,
首先,我现在要把这个“1”呢,传到第二个控制器,

传到第二个控制器,然后呢,再把第二个控制器的这个Title,
NavigationItem的这个Title,去设置一下,改成“1的联系人”,
但是,这个时候,好,我们现在啊,

点“注销”,回到第一个控制器,
当我点击“登录”的时候,

我们确定,我要跳到B控制器的对象,
1)第一步:我要在B里边儿,声明我要传值的类型,这是第一步啊,我要传什么,我要传一个String,给你,然后,到时候,你再去设置它,
2)这个时候,首先,第一步,

我在我的第二个控制器,

B控制器,联系人的控制器,的“点儿”h文件里边儿,

先声明一个String类型的属性,

先声明一个String类型的变量啊,叫做username,

3)好,然后呢,接下来啊,我只需要,去拿到B控制器,然后给它去赋值,就OK了,
那么我们刚才啊,当我们点击屏幕的时候,我们跳到B控制器,所以呢,我们点击屏幕的时候,应该可以拿到B控制器对象,
但是,我们这个里边儿,

我们这个里边儿,

我们是通过Storyboard去跳转的,我们点击“登录”以后,怎么样去跳转呢,

我们是通过performSegueWithIdentifier:去跳转,

通过这个方法去跳转的,
我们并没有说,明显的去创建B控制器对象,
那这个时候呢,我们现在啊,我们在这个里边儿,并不像刚才一样,
不能直接拿到B控制器对象,
3.我们现在需要做的呢,
就是想办法儿去取到我的目标控制器,
也就是说那个B控制器,
我要想办法儿,取到它,然后,还要去赋值,
它就应该传完了,
二、这个时候,我们再来看ppt,

1.我要往后面儿去说了,
还是关于Segue的一些东西,

然后,

然后呢,Segue,里边儿啊,

好,Segue里边儿,有三个属性,这个说过了,
1)id
2)sourceViewController
3)destinationViewController

好,我们说,利用performSegueWithIdentifier:这个方法,来去执行某一个Segue,然后完成去跳转,这么一个功能,
2.好,我们来说一下,Segue,performSegueWithIdentifier:这个方法,完整的一个执行过程,也就是说,在系统里头,它到底都干了点儿啥东西,好,它分为啊,几个大步骤,
1)首先:你执行这句话的时候,

[self performSegueWithIdentifier:@“login2contacts” sender:nil];
self:是来源控制器
2)然后呢,第一:根据你传过来的这个id,@“login2contacts”,

去Storyboard中找到对应的线,
3)然后,去创建一个Segue对象,

好,这是第一步,当你执行这句话的时候啊,系统第一步,找到这个Storyboard里边儿,的这个id,的这根儿线,然后,创建出来这个Segue对象,
4)然后,第二步:设置Segue对象的sourceViewController(来源控制器),

文章来源:https://blog.csdn.net/madoca/article/details/135523235
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:chenni525@qq.com进行投诉反馈,一经查实,立即删除!