我在第一次打开应用时使用WSCoachMarksView给我的用户一个演练,我显然只希望第一次运行,之后再也不会。我按照文档中的说明进行操作,该文档告诉您将{I}中的相应代码放在viewDidAppear
中,以便它只运行一次,但它似乎无法正常工作。
每次应用程序打开时,它仍会贯穿整个演练。有没有什么我没有正确检测以前运行的应用程序并设置BOOL以便它不会再次运行?
SearchViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
// Setup coach marks
NSArray *coachMarks = @[
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{50,168},{220,45}}],
@"caption": @"Just browsing? We'll only notify you periodically of new matches. Need it soon? We'll notify you more frequently, and match you with items that are closer to you."
},
];
self.coachMarksView = [[WSCoachMarksView alloc] initWithFrame:self.tabBarController.view.bounds coachMarks:coachMarks];
[self.tabBarController.view addSubview:self.coachMarksView];
self.coachMarksView.animationDuration = 0.5f;
self.coachMarksView.enableContinueLabel = YES;
[self.coachMarksView start];
}
- (void)viewDidAppear:(BOOL)animated {
// Show coach marks
BOOL coachMarksShown = [[NSUserDefaults standardUserDefaults] boolForKey:@"WSCoachMarksShown"];
if (coachMarksShown == NO) {
// Don't show again
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WSCoachMarksShown"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Show coach marks
[self.coachMarksView start];
}
}
答案 0 :(得分:1)
在viewDidLoad中,无论您在NSUserDefaults中设置了什么,都始终开始介绍。检查viewDidAppear是正确的,但它已经在那时播放