我正在开发我的应用程序,但我需要一些帮助。我在Objective C中需要一个“类似php的会话”(不使用互联网连接)我考虑过全局变量,但我的应用程序似乎在重新加载视图时重置了它们。这是我当前的代码
SecondViewController.h
@interface SecondViewController : UIViewController
{
NSString * string;
}
第二视图控制器.m
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
if (! [string isEqualToString:@"Hello"])
{
NSLog(@"Hello");
string = @"Hello";
}
else
{
NSLog(@"Bye");
}
}
@end
但是每次我重新加载 SecondViewController 时,“字符串”都会重置为其默认值。我正在寻找我们在 php 中使用的东西 (ae $_SESSION['string'] = 'hello')