1

我在装有 iOS 5 的 iPad 上展示了 UIActionSheet,没有任何问题。现在,在我的 iPad 上安装了 iOS 6 后,应用程序在执行相同操作时会崩溃。我不知道如何解决这个问题,因为我的代码没有改变并且堆栈跟踪很难理解。有人遇到同样的问题吗?

我的初始化代码UIActionSheet

UIActionSheet *menu = [[[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"ExportMethod", @"") delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", @"") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"ExportMethodMail", @""), NSLocalizedString(@"ExportMethodiTunes", @""), nil] autorelease];
self.actionSheet = menu;

呈现UIActionSheet

[self.actionSheet showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];

我还尝试了其他可能的调用:

[self.actionSheet showInView:self.view];
[self.actionSheet showFromTabBar:self.tabBarController.tabBar];
[self.actionSheet showFromRect:self.view.bounds inView:self.view animated:YES];

但是,该应用程序总是在此行崩溃并显示以下消息:

Thread 6: EXC_BAD_ACCESS (code = 1, adress = 0xcc)

如果我在没有调试器的情况下运行应用程序,我会得到以下堆栈跟踪:

 Thread 5 Crashed:
 0   libicucore.A.dylib             0x39620570 ucol_getVersion + 0
 1   TextInput                      0x36aed21a   KB::WordTrie::dictionary_versions_ok(KB::ReadOnlyDataFile const*) const + 62
 2   TextInput                      0x36aecfa4 KB::WordTrie::load(KB::String const&) + 276
 3   TextInput                      0x36ae6490 <redacted> + 12
 4   TextInput                      0x36e50cae <redacted> + 54
 5   TextInput                      0x36e50c4c <redacted> + 40
 6   TextInput                      0x36addf68 TIInputManager::load_dictionaries(KB::String const&, KB::String const&, bool) + 20
 7   TextInput                      0x36aeefbc <redacted> + 216
 8   TextInput                      0x36aeec02 <redacted> + 498
 9   UIKit                          0x356ccf7a <redacted> + 158
 10  UIKit                          0x356cbfce <redacted> + 398
 11  UIKit                          0x356cbbe2 <redacted> + 374
 12  UIKit                          0x356ca4b4 <redacted> + 460
 13  UIKit                          0x356ca1a6 <redacted> + 146
 14  UIKit                          0x3593001c <redacted> + 264
 15  UIKit                          0x3593045c <redacted> + 568
 16  UIKit                          0x3593468c <redacted> + 564
 17  UIKit                          0x35934a94 <redacted> + 136
 18  UIKit                          0x35934e5e <redacted> + 250
 19  EasyTag                        0x0002365e -[GameDetailController exportGameAsCSV] (GameDetailController.m:598)

exportGameAsCSV方法UIActionSheet是提出的。

4

1 回答 1

6

谢谢你的回答。问题是我不在 UI 线程中。根据苹果的文档:

Important The UIKit classes are generally not thread safe. All drawing-related operations should be performed on your application’s main thread.

下面的代码解决了这个问题:

dispatch_async(dispatch_get_main_queue(), ^{

    [self.actionSheet showFromBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];

 });
于 2012-10-08T09:03:40.460 回答