我有两个文本字段。一个是用户名,第二个是密码。当我提交两个值时传递给 Json。如果你的用户名和密码在数据库中。我得到响应用户名。 但是现在我需要将用户名传递给我应用程序中的所有 ViewControllers 请帮助我 感谢高级。请给我任何想法。
最佳答案
您可以在 AppDelegate 文件中创建变量。
在 AppDelegate.h 文件中
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
NSString *username;
}
@property(nonatomic,retain)NSString *username;
在 AppDelegate.m 文件中
@implementation AppDelegate
@synthesize username;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//your other code.....
self.username=@"";
}
创建 AppDelegate 对象并在您向 json 提交值的地方设置它的值
AppDelegate *delegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.username = @"ABC";
在所有 View Controller 中创建 AppDelegate 对象并访问用户名变量
AppDelegate *delegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
nslog(@"%@",delegate.username);
关于ios - 如何将字符串值传递给我应用程序中的所有 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25643117/