使用IOS 6在iPad上展示N动作表时崩溃

时间:2012-10-08 08:14:47

标签: ios objective-c ipad uikit uiactionsheet

我在iPad上用iOS 5呈现了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的展示位置。

1 个答案:

答案 0 :(得分:6)

感谢您的回答。问题是我不是在UI线程中。根据Apple的文档:

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];

 });