UIActionSheet 控制器在 iPad 上崩溃,但在 iPhone 上运行正常
我一直在尝试将 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 上程序此时崩溃了。
I've been trying to work a UIActionSheet into my App. The idea is, if you exited the app in a certain state, it would popup on launch and ask you if you'd like to continue or reset. Here's the code:
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];
}
This is in viewDidLoad. And the actual Code action is:
- (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];
}
}
It all seems pretty straight forward, but for some reason it runs on the iPhone with no problem but on the iPad the program crashes at this point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这个是一个大胖 DOH!我错误地实现了 iPad XIB,重新开发它们后,它按设计工作了。
Ok this one get's a big fat DOH! I had incorrectly implemented the iPad XIB, after redeveloping them this works as designed.