【发布时间】:2026-01-27 11:30:01
【问题描述】:
我使用以下代码来初始化 UIWebView 的实例:
-(void)viewDidLoad {
[super viewDidLoad];
UIWebView *webView;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 964)]; //crash
} else {
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];
}
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
很奇怪,上面的代码在iphone模拟器上可以运行,但是在ipad模拟器上会崩溃。我的 xcode 是 3.2.4。你能提供任何线索吗?提前致谢!
崩溃日志:
flushCaches 中的 0 0x031b5574
#1 remethodizeClass 中的 0x031b38fc
_read_images 中的 #2 0x031b60ea
map_images_nolock 中的 3 0x031c3784
map_images 中的 #4 0x031b5724
#5 0x8fe03f2d 中__dyld__ZN4dyldL18notifyBatchPartialE17dyld_image_statesbPFPKcS0_jPK15dyld_image_infoE
6 0x8fe0decd 在 __dyld__ZN11ImageLoader4linkERKNS_11LinkContextEbbRKNS_10RPathChainE
7 0x8fe056af在__dyld__ZN4dyld4linkEP11ImageLoaderbRKNS0_10RPathChainE结果,#8 0x8fe0b242在__dyld_dlopen结果,#9 0x9754a868在dlopen的结果,#10 0x0063b8e6在initWebUILocalStorageSupport结果,在#11 0x0063a0d6 - [UIWebView的_webViewCommonInit:]结果,#12 0x0063abfd在 -[UIWebView initWithFrame:]
#13 0x0002c467 在 -[WebViewControllerviewDidLoad] 在 WebViewController.m:55
#14 0x00525f85 in -[UIViewController view]
#15 0x0052439f in -[UIViewController contentScrollView]
#16 0x00532fee in -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]
#17 0x00531f40 in -[UINavigationController _layoutViewController:]
#18 0x00533f39 in -[UINavigationController _startTransition:fromViewController:toViewController:]
#19 0x0052dfa1 in -[UINavigationController _startDeferredTransitionIfNeed] 0x00673c8a in -[UILayoutContainerView layoutSubviews]
#21 0x02b10916 in -[CALayer layoutSublayers]
#22 0x02b10625 in CALayerLayoutIfNeeded
#23 0x02b3b0e7 in -[CALayer layoutIfNeeded]
#24 0x00527296 in -[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:]25 0x004afef1 in -[UIWindow _setRotatableClient:toOrientation:duration:force:]
#26 0x00736425 in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:]
27 0x005297ac in -[UIViewController presentModalViewController:withTransition:]
#28 0x00522e70 in-[UIViewController _tryRecursivelyPresentModalViewController:withTransition:]
#29 0x0052901d in -[UIViewController presentModalViewController:withTransition:]
#30 0x0002b8b4 in -[TweetViewController showLocation:] at TweetViewController.m:608
#31 0x0048dcee in -[UIApplication sendAction:to:from:forEvent:]
#32 0x0050743e in -[UIControl sendAction:to:forEvent:]
#33 0x005098c0 in -[UIControl(Internal) _sendActionsForEvents:withEvent:]
#34 0x0050846d in -[UIControl touchesEnded:withEvent:]
#35 0x0071aaad in _UIGestureRecognizerUpdateObserver
#36 0x03016a52 in __CFRunLoopDoObservers
#37 0x02fe3345 in CFRunLoopRunSpecific
#38 0x02fe28a8 in CFRunLoopRunInMode39 0x034d089d in GSEventRunModal
#40 0x034d0962 in GSEventRun
#41 0x00498372 in UIApplicationMain
42 0x00002dd8 在 main.m:14
【问题讨论】:
-
请向我们提供崩溃日志。代码本身看起来不错。
-
@Schot,感谢格式化
-
看起来是其他原因导致崩溃...,同意 Stream Trout。无论如何,如果它是一个指针,将局部变量初始化为 nil 通常是个好主意。
-
@Steam & SegFault,感谢重播。附上日志。
标签: iphone ipad uiwebview crash