开发者

Program to pass string from one view to another?

开发者 https://www.devze.com 2023-01-10 10:43 出处:网络
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.

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.

开发者_C百科 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

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.

Thanks James


you can make object of second view and can pass string to it

view2object.view2string=@"anything" or label.text;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号