程序将字符串从一个视图传递到另一个视图? [英] Program to pass string from one view to another?

查看:91
本文介绍了程序将字符串从一个视图传递到另一个视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个视图的iphone应用程序
第一个视图有一个按钮,现在
i想要在单击该按钮时显示第二个视图上按钮的标题。

我怎么能这样做,因为如果我们将标题保存为字符串,那么当加载第二个视图时字符串会被清空?

I have an iphone application containing two views The first view have a button, now i want to show the title of the button on the second view when that button is clicked.
How can i do it because if we save the title into a string ,the string get emptied when second view is loaded ?

推荐答案

在接口中声明字符串并创建一个属性:

In the interface declare the string and make a property:

 @interface MyViewController : UIViewController {


   NSString *string_i_want_to_set;  

 }

 @property (nonatomic, retain) NSString *string_i_want_to_set;

 @end

在实现中合成@implementation之后的字符串MyViewController就像这个:

In the implementation synthesize the string after @implementation MyViewController like this:

 #import "MyViewController.h"


 @implementation MyViewController

 @synthesize string_i_want_to_set;

 // OTHER CODE HERE...

 @end

然后当您分配/初始化视图控制器时,您可以设置如下属性:

Then when you alloc/init the view controller you can set the property like this:

MyViewController *myVC = [[MyViewController alloc] init];
myVC.string_i_want_to_set = @"...."

希望这能为您提供更多细节。

Hope this gives you more detail.

谢谢
James

Thanks James

这篇关于程序将字符串从一个视图传递到另一个视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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