将字符串从一个视图控制器传递到另一个 Tabbar 控制器
我有一个字符串数据必须发送到另一个视图控制器 - 在我的例子中是一个 tabbarcontroller。我在发送时收到空数据。 下面是代码片段:
ViewController.h
#import <UIKit/UIKit.h>
@class ViewController2;
@interface ViewController1 : UIViewController{
@private
ViewController2 *suiteNo;
}
@property(nonatomic,retain) ViewController2 *viewController2;
-(IBAction)suiteNumber:(UIButton *)sender;
@end
我在.m文件中声明如下
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];
有什么地方我犯了错误吗?如果我错了,请纠正我。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要在 viewcontroller2 中创建 suiteNum 属性,而是在 appdelegate 中声明 suiteNum 并将字符串值从 viewcontroller1 复制到 suiteNum ,
如下所示:=
AppDelegate *appdelegate1= (AppDelegate *)[[UIApplication sharedApplication] delegate];
appdelegate1.suiteNum= [[发件人标题标签]文本];
当 viewcontroller2 出现时,它的 viewwillappear 委托会被覆盖为
AppDelegate *appdelegate1= (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *firstURL=appdelegate1.suiteNum;
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;