好吧,我有这 2 个变量,一个 NSString 和一个 NSMutable Array,这是我希望在所有选项卡中成为全局的值。到目前为止,我只有一个(NSString)并且可以正常获取它的值。不,我尝试再拥有一个变量,我得到(空)值。
这是我的代码:
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic,retain) NSString *myDate;
@property (nonatomic,copy) NSMutableArray *tracks_condition;
@end
当我分配值时在 HomeView.m 中
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
parsed_date=[res objectForKey:@"date"];
NSLog(@"Date:%@",parsed_date);
delegate.myDate = parsed_date;
NSString *parsed_track=[res objectForKey:@"Data1"];
[delegate.tracks_condition addObject:parsed_track];
NSLog(@"Track 0 Static:%@",parsed_track);
NSLog(@"Track 0:%@",[delegate.tracks_condition objectAtIndex:0]);
parsed_date 正在正常打印出来,我可以在其他选项卡中访问它。
但我得到: Track 0 Static:0 Track 0: (null)
我不明白为什么,因为我将它作为对象添加到 MutableArray 中。当然,我在其他所有选项卡中都得到 (null)。
你能帮助我吗?我更喜欢修复该代码而不是提出完全不同的建议,因为我在 IOS 方面不是很有经验。除非它是那么容易。