【问题标题】:Crash after dismissModalViewControllerAnimated on iPad在 iPad 上dismissModalViewControllerAnimated 后崩溃
【发布时间】:2011-11-28 17:52:37
【问题描述】:

我的 iPad 应用程序遇到了意外问题,我不确定是我做错了什么还是这是正常的设备行为 -

  1. TableViewController -> didSelectRowAtIndexPath -> presentModalViewController
  2. modalView 上的取消/保存操作 -> dismissModalViewControllerAnimated -> 工作正常。

然而——

  1. TableViewController -> didSelectRowAtIndexPath -> presentModalViewController
  2. 将设备方向更改为 90 度(意味着当前视图方向与父视图控制器方向不同
  3. 取消对modalView的操作 -> dismissModalViewControllerAnimated -> 崩溃

我尝试在必要时使用 setTranform 修改模式视图 - 它确实更改了视图,但不会更改 self.interfaceOrientation 值。

我相信解决此问题的正确方法是将 self.interfaceOrientation 值修改为 90 度,但我真的不知道该怎么做 - 除非有更简单的解决方案。


附上调试输出-也许它可以帮助...

2011-11-29 11:09:35.981 myApp [65933:c203] -[UIDeviceWhiteColor count]: unrecognized selector sent to instance 0x7191bf0

2011-11-29 11:09:35.985 myApp [65933:c203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceWhiteColor count]: unrecognized selector sent to instance 0x7191bf0'

*** Call stack at first throw:
(
    0   CoreFoundation                      0x011dc5a9 __exceptionPreprocess + 185    
    1   libobjc.A.dylib                     0x015f7313 objc_exception_throw + 44   
    2   CoreFoundation                      0x011de0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x0114d966 ___forwarding___ + 966
    4   CoreFoundation                      0x0114d522 _CF_forwarding_prep_0 + 50
    5   myApp                               0x0000eac4 -[myTableViewController tableView:numberOfRowsInSection:] + 68
    6   UIKit                               0x005eb2b7 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834
    7   UIKit                               0x005ed8a4 -[UITableViewRowData rectForFooterInSection:] + 108
    8   UIKit                               0x005ed130 -[UITableViewRowData heightForTable] + 60
    9   UIKit                               0x004ada56 -[UITableView(_UITableViewPrivate) _updateContentSize] + 333
    10  UIKit                               0x004a50c0 -[UITableView _rectChangedWithNewSize:oldSize:] + 559
    11  UIKit                               0x004a3917 -[UITableView setFrame:] + 266
    12  UIKit                               0x00463a03 -[UIView(Geometry) resizeWithOldSuperviewSize:] + 385
    13  UIKit                               0x0046797b -[UIView(Geometry) resizeSubviewsWithOldSize:] + 273
    14  UIKit                               0x00463e94 -[UIView(Geometry) setFrame:] + 497
    15  UIKit                               0x004de475 -[UIViewControllerWrapperView setFrame:] + 79
    16  UIKit                               0x00463a03 -[UIView(Geometry) resizeWithOldSuperviewSize:] + 385
    17  UIKit                               0x0046797b -[UIView(Geometry) resizeSubviewsWithOldSize:] + 273
    18  UIKit                               0x00463e94 -[UIView(Geometry) setFrame:] + 497
    19  UIKit                               0x00463a03 -[UIView(Geometry) resizeWithOldSuperviewSize:] + 385
    20  UIKit                               0x0046797b -[UIView(Geometry) resizeSubviewsWithOldSize:] + 273
    21  UIKit                               0x004641c5 -[UIView(Geometry) setBounds:] + 623
    22  UIKit                               0x00601f51 -[UILayoutContainerView setBounds:] + 78
    23  UIKit                               0x004df4f7 -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:] + 440
    24  UIKit                               0x0045655f -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 4347
    25  UIKit                               0x006dd619 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 1381
    26  UIKit                               0x004e3385 -[UIViewController _dismissModalViewControllerWithTransition:from:] + 2058
    27  UIKit                               0x004dfeb8 -[UIViewController dismissModalViewControllerWithTransition:] + 940
    28  myApp                               0x00014a04 -[myModalViewController cancelAdding:] + 132
    29  UIKit                               0x0042e4fd -[UIApplication sendAction:to:from:forEvent:] + 119
    30  UIKit                               0x004be799 -[UIControl sendAction:to:forEvent:] + 67
    31  UIKit                               0x004c0c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    32  UIKit                               0x004bf7d8 -[UIControl touchesEnded:withEvent:] + 458
    33  UIKit                               0x00452ded -[UIWindow _sendTouchesForEvent:] + 567
    34  UIKit                               0x00433c37 -[UIApplication sendEvent:] + 447
    35  UIKit                               0x00438f2e _UIApplicationHandleEvent + 7576
    36  GraphicsServices                    0x02ce2992 PurpleEventCallback + 1550
    37  CoreFoundation                      0x011bd944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    38  CoreFoundation                      0x0111dcf7 __CFRunLoopDoSource1 + 215
    39  CoreFoundation                      0x0111af83 __CFRunLoopRun + 979
    40  CoreFoundation                      0x0111a840 CFRunLoopRunSpecific + 208
    41  CoreFoundation                      0x0111a761 CFRunLoopRunInMode + 97
    42  GraphicsServices                    0x02ce11c4 GSEventRunModal + 217
    43  GraphicsServices                    0x02ce1289 GSEventRun + 115
    44  UIKit                               0x0043cc93 UIApplicationMain + 1160
    45  myApp                               0x00001c5a main + 170
    46  myApp                               0x00001ba5 start + 53
)

终止调用抛出异常当前语言:自动;目前客观-c

我的tableView numberOfRowsInSection:

return [iphoneWordPlistUnsorted count];

在 .h 文件中声明并在 viewWillAppear 方法中分配:

[super viewWillAppear:animated];
documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    path = [documentsDirectory stringByAppendingFormat:WORDS_PLIST_IPHONE];
    self.tableView.sectionHeaderHeight = 63;
    self.tableView.rowHeight = 80;
}
else
{
    path = [documentsDirectory stringByAppendingFormat:WORDS_PLIST_IPAD];
    self.tableView.sectionHeaderHeight = 94;
    self.tableView.rowHeight = 120;
}

iphoneWordPlistUnsorted = [[NSMutableArray alloc] initWithContentsOfFile:path];
iphoneWordsPlist = [iphoneWordPlistUnsorted sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

[iphoneWordPlistUnsorted removeAllObjects];
int i;
for (i=0; i < [iphoneWordsPlist count]; i++) {
    [iphoneWordPlistUnsorted addObject:[iphoneWordsPlist objectAtIndex:i]];
}

[self.tableView reloadData];

非常感谢,

嘟嘟

【问题讨论】:

  • 崩溃到底是什么,发生了什么异常,堆栈跟踪是什么?根据崩溃情况,这也可能与内存管理问题等其他想法有关。
  • 嗨,这是我收到的错误:2011-11-29 09:09:25.337 [65805:c203] -[UITextRenderingAttributes count]: unrecognized selector sent to instance 0x56339e0 2011-11-29 09 :09:25.340 [65805:c203] ***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UITextRenderingAttributes count]:无法识别的选择器发送到实例0x56339e0'当我单击“取消/保存”按钮时会发生这种情况调用dismissModalViewControllerAnimated。
  • 再一次 - 它不会发生,两个视图都在相同的方向 - 只有当它们有 90/270 度的差异时。感谢您的帮助
  • 这听起来可能是多线程问题(变量的线程不安全访问)或内存损坏。您是否通过使用 NSZombieEnabled 的工具运行您的应用程序?除非已运行轮换代码并移动了一些东西,否则内存损坏可能不会引发错误。
  • 我添加了调试输出作为答案 - 也许它可以帮助...

标签: objective-c ipad ios4 presentmodalviewcontroller


【解决方案1】:

您的 iphoneWordPlistUnsorted 对象正在被释放,内存正在被重新分配为其他东西。在启用僵尸的情况下运行(在 Xcode 或 Instruments 中)将帮助您查明错误。

【讨论】:

  • 好的,我看到了。我有 - [iphoneWordPlistUnsorted release];关于 viewwilldisappear 方法 - 这可能是原因吗?
  • 可能。确保在 Instruments 中与僵尸一起奔跑。
猜你喜欢
  • 1970-01-01
  • 2011-12-10
  • 2012-11-26
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多