简体   繁体   中英

Passing a string from one viewcontroller to another Tabbarcontroller

I have a string data that has to be sent to another viewcontroller - In my case is a tabbarcontroller. I received a null data while sending. Below is the code snippet:

ViewController.h

#import <UIKit/UIKit.h>
@class ViewController2;

@interface ViewController1 : UIViewController{

@private
ViewController2 *suiteNo;

}

@property(nonatomic,retain) ViewController2 *viewController2;


-(IBAction)suiteNumber:(UIButton *)sender;
@end

I have declared in the .m file as below

ViewController1.m

@synthesize viewController2;

//data accessed
self.viewController2.suiteNum = [[sender titleLabel] text];

ViewController2.h

#import <UIKit/UIKit.h>



@interface ViewController2 : UIViewController{

NSString *suiteNum;

  }

 @property(nonatomic,copy)NSString *suiteNum;
 @end

ViewController2.m

@synthesize suiteNum;

//the passed string is used here
NSString *firstURL = [segmentOneURL stringByAppendingString:suiteNum];

Is there any place where i made a mistake? Please correct me if im wrong. Thank you.

Instead of making suiteNum property in viewcontroller2 ,declare suiteNum in appdelegate and copy the string value from viewcontroller1 to suiteNum

like this:= AppDelegate *appdelegate1= (AppDelegate *)[[UIApplication sharedApplication] delegate];

appdelegate1.suiteNum= [[sender titleLabel] text];

and when viewcontroller2 appears override it's viewwillappear delegate as

AppDelegate *appdelegate1= (AppDelegate *)[[UIApplication sharedApplication] delegate];

NSString *firstURL=appdelegate1.suiteNum;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM