我有一个标签,用户将设置该号码后,该用户点击按钮的号码将被存储在数字variable.in appdelegate.m我想访问已设置的号码。 例如标签的输入是9:25 这里是我所做的。我认为在appdelegate.m中声明我的viewcontroller是错误的,但我不知道该怎么做。退出程序(后台输入)后可以维护变量吗?
ShowOfNotificationViewController.h
@property(strong,nonatomic) NSString *numbers;
ShowOfNotificationViewController.m
@implementation ShowOfNotificationViewController
@synthesize numbers;
- (IBAction)setTime:(id)sender {
numbers=TimeLabel.text;
}
ShowOfNotificationAppDelegate.m
#import "ShowOfNotificationAppDelegate.h"
#import "ShowOfNotificationViewController.h"
- (void)applicationDidEnterBackground:(UIApplication *)application
{
ShowOfNotificationViewController *m;
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSArray *listItems = [m.numbers componentsSeparatedByString:@":"];
NSNumber * myNumber1 = [f numberFromString:listItems[0]];
NSNumber * myNumber2 = [f numberFromString:listItems[1]];
NSLog(@"%@",myNumber1);
NSLog(@"%@",myNumber2);
}
输出为NULL,NULL
<在下面插入关于NSUserDefaults的回答> – CodaFi 2013-03-10 12:03:17
抱歉,我不明白你的意思 – Nickool 2013-03-10 12:03:45
让我看看NSNumberFormatter的初始化f – CodaFi 2013-03-10 12:13:19