且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

全局变量读/写访问

更新时间:2023-11-30 11:50:34

是的,有很多简单的方法可以解决这个问题.....

Ya , there is much a easy way to handle this.....

您可以采用全局变量

在您的Delegate.h文件中声明您的变量:

In your Delegate.h file declare your variable:

@interface Smoke_ApplicationAppDelegate : NSObject {

UIWindow *window;
UINavigationController *navigationController;
NSString *messageString;  //This would be your String Variable
} @property(nonatomic,retain)NSString *messageString;

第二次出现在Delegate.m文件中

Secondly in Delegate.m file

@implementation Smoke_ApplicationAppDelegate

@synthesize window; @synthesize navigationController; @synthesize messageString; // 

在这里合成它.

完成.现在,您可以在所有/任何所需的类中使用此字符串变量.

This is Done .Now you can use this String Variable in All/any class you want..

要使用此全局变量.

只需导入您的Delegate文件即可使其成为obj....

Just import you Delegate file make the obj of it....

import "DelegateFile.h"

@implementation About

DelegateFile *appDel;

现在在您的班上.m

-(void)viewDidLoad { [super viewDidLoad];

appDel=[[UIApplication sharedApplication]delegate];

}

现在,您可以通过此对象在班上的任何地方访问它:

Now you can access it anywhere in your class by this Object:

appDel.messageString

只要小心地遵循我的步骤,我的手指承受了很大的痛苦后,我相信这肯定会为您提供帮助.....

Just follow my Steps Carefully After giving so much pain to my finger, I am sure this is definitely going to help you.....

过着轻松的生活,