我有一個標籤,用戶將設置該號碼後,該用戶點擊按鈕的號碼將被存儲在數字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