将字符串从一个视图控制器传递到另一个 Tabbar 控制器

发布于 2024-12-29 18:36:05 字数 991 浏览 1 评论 0原文

我有一个字符串数据必须发送到另一个视图控制器 - 在我的例子中是一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ヅ她的身影、若隐若现 2025-01-05 18:36:05

不要在 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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文