UIActionSheet 控制器在 iPad 上崩溃,但在 iPhone 上运行正常

发布于 2024-09-18 17:01:49 字数 1403 浏览 4 评论 0原文

我一直在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦途 2024-09-25 17:01:49

好吧,这个是一个大胖 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文