我一直在尝试将UIActionSheet应用到我的应用程序中。这个想法是,如果您在特定状态下退出应用程序,它会在启动时弹出,并询问您是否要继续或重置。这是代码:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
continueYesNo = [prefs boolForKey:@"keyContinueMeeting"];
if (continueYesNo) {
NSString *message_continue = [[NSString alloc] initWithFormat:@"Do you want to Continue the Prior Meeting"];
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:message_continue
delegate:self
cancelButtonTitle:@"Reset"
destructiveButtonTitle:@"Continue"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
[message_continue release];
}
这是在viewDidLoad中。实际的代码行动是:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
Wasted_TimeAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (buttonIndex != [actionSheet cancelButtonIndex]) {
delegate.continueMeeting = YES;
[prefs setBool:YES forKey:@"keyContinueMeeting"];
[ [NSUserDefaults standardUserDefaults] synchronize];
} else {
delegate.continueMeeting = NO;
[prefs setBool:NO forKey:@"keyContinueMeeting"];
[ [NSUserDefaults standardUserDefaults] synchronize];
}
}
这一切看起来都非常简单,但出于某种原因,它在iPhone上运行没有问题,但在iPad上程序崩溃了。
答案 0 :(得分:0)
好的,这是一个很胖的DOH!我错误地实现了iPad XIB,在重新开发之后,它按照设计工作。