iPhone开发-使用其他视图中的数据 [英] iPhone Development - Using Data from another view

查看:32
本文介绍了iPhone开发-使用其他视图中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个视图:由textview(用户输入)和按钮(按此按钮可使您进入第二个视图)

First view: consists of a textview(user input) & button(pressing on this button takes u to the second view)

第二个视图:由标签组成

Second View: consists of a label

我希望标签显示用户在第一个视图中写的内容.

i want the label to display what the user wrote in the first view.

推荐答案

将其放在SecondViewController的.h文件中

Take this in .h file in SecondViewController

NSString *strUserInput;

在seconviewcontroller中进行以下功能

Make below function in seconviewcontroller

-(void)setUserInput:(NSString *)strEntered{
    strUserInput=strEntered;
}

现在在第一个视图控制器中执行以下操作:

Now In first view controller do like this:

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];

[objSecond setUserInput:txtUserInput.text];
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];

现在,在secondViewController viewWillAppear方法中编写此代码.

Now, In secondViewController viewWillAppear Method write this.

-(void)viewWillAppear:(BOOL)animated{
      lblUserInput.text = strUserInput;
}

请在我手写时检查拼写错误.希望有帮助.

Please check spelling mistakes as I hand written this. Hope this help.

如果您不使用navigationContoller,则可以执行以下操作.

If you are not using navigationContoller then you can do something like this.

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
[objSecond setUserInput:txtUserInput.text];
[objSecond viewWillAppear:YES];
[self.view addSubview:objSecond];
[objSecond release];

这篇关于iPhone开发-使用其他视图中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆