標籤:
1.由於項目的需要,我今天學習了新手的引導,接下我來說下新手引導的使用方法:(在程式中運行一次)接下來是實現代碼:
在AppDelegate.m 的代碼:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIViewController *root;
BOOL answer= [[NSUserDefaults standardUserDefaults]boolForKey:@"answer"];
if (!answer) {
root = [[WecomeViewController1 alloc]init]; //歡迎介面的,就是介紹產品的新特性
}
else{
root = [[TestViewController alloc]init];
}
self.window.rootViewController = root;
[self.window makeKeyAndVisible];
return YES;
}
在需要調用的的時候實現的代碼為:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSString *anwerLabel = self.anwerLabel.text;
if([anwerLabel isEqualToString:@""]){
[self showString:@"答案錯誤,不要太生氣!!"];
return;
}
if([anwerLabel isEqualToString:@"1234"]){
[self showString:@"恭喜你回答正確!!"];
TestViewController *testVC = [[TestViewController alloc]init];
[self presentViewController:testVC animated:NO completion:nil];
//在這裡設定判斷是否為第一次,然後設定同步
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"answer"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
}
希望可以協助有需要的人!歡迎你們提出寶貴的意見!!
IOS中新手引導的實現