2010-10-15 65 views
0

崩潰我用下面的代碼初始化的UIWebView實例:UIWebView的初始化iPad上

-(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。你能否提供任何線索?提前致謝!

崩潰日誌:

0 flushCaches 0x031b5574
#1 0x031b38fc在_read_images

3 map_images_nolock 0x031c3784 remethodizeClass
#2 0x031b60ea
#4 0x031b5724在map_images
#5 0x8fe03f2d在

__dyld__ZN4dyldL18notifyBatchPartialE17dyld_image_statesbPFPKcS0_jPK15dyld_image_infoE

6 0x8fe0decd在__dyld__ZN11ImageLoader4linkERKNS_11LinkContextEbbRKNS_10RPathChainE在__dyld__ZN4dyld4linkEP11ImageLoaderbRKNS0_10RPathChainE

7 0x8fe056af#8在__dyld_dlopen
#9 0x9754a868中的dlopen
#10 0x0063b8e6在initWebUILocalStorageSupport
#11 0x0063a0d6 0x8fe0b242 - [UIWebView的_webViewCommonInit:]
#12 0x0063abfd在 - [UIWebView initWithFrame:]
#13 0x0002c467 in - [WebViewController

viewDidLoad] at WebViewController.m:55
#14 0x00525f85在 - [UIViewController的視圖]
在#15 0x0052439f - [UIViewController中contentScrollView]在
#16 0x00532fee - [UINavigationController的 _computeAndApplyScrollContentInsetDeltaForViewController:]
#17 0x00531f40在 - [UINavigationController的_layoutViewController:]在
#18 0x00533f39 - [UINavigationController的_startTransition:fromViewController:toViewController:]
#19 0x0052dfa1在 - [UINavigationController的_startDeferredTransitionIfNeeded]
#20 0x00673c8a在 - [UILayoutContainerView layoutSubviews]
#21 0x02b10916在 - [CALayer的layoutSublayers]
#22 0x02b10625在CALayerLayoutIfNeeded
#23 0x02b3b0e7在 - [CALayer layoutIfNeeded]
#24 0x00527296在 - [UIViewController中 窗口:willAnimateRotationToInterfaceOrientation:持續時間:]

25 0x004afef1在 - [一個UIWindow _setRotatableClient:toOrientation:持續時間:力:]
#26 0x00736425在 - [UIWindowController過渡:fromViewController:toViewController:目標:didEndSelector:]

27 0x005297ac在 - [UIViewController中presentModalViewController:withTransition:]
#28 0x00522e70在

- [UIViewController中_tryRecursivelyPresentModalViewController:withTransition:]
#29 0x0052901d在 - [UIViewController presentModalViewController:withTransition:]
#30 0x0002b8b4在 - [TweetViewController showLocation:]在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在 - [UIControl touchesEnded:withEvent:方法]
#35 0x0071aaad在
#36 0x03016a52在__CFRunLoopDoObservers
#37 0x02fe3345在CFRunLoopRunSpecific
#38 0x02fe28a8在CFRunLoopRunInMode _UIGestureRecognizerUpdateObserver

39 0x034d089d在GSEventRunModal
# 40 GSEventRun中的0x034d0962
#41 0x00498372 in UIApplicationMain

42主0x00002dd8在main.m文件:14

+2

請給我們提供崩潰日誌。代碼本身看起來很好。 – SteamTrout 2010-10-15 13:51:47

+0

@Schot,感謝格式 – mobguang 2010-10-15 14:10:28

+0

看起來像別的東西導致崩潰...,同意流鱒魚。無論如何,如果它的指針初始化局部變量爲零,通常是個好主意。 – SegFault 2010-10-15 14:13:50

回答

0

難道你想改變什麼的的WebView initWithFrame?這不是webview的錯,這是用框架創建它的正確方法。 你可以發佈其餘的控制器?

+0

我剛剛發現AutorotateToInterfaceOrientation方法會先被調用,然後viewDidLoad方法會在控制器初始化期間被調用。你認爲我錯過了iPad的自動旋轉指定要求的任何設置?謝謝。 – mobguang 2010-10-15 14:47:04

+0

我刪除了AutorotateToInterfaceOrientation方法,然後可以創建沒有崩潰的webView。我只是想將我的應用程序從iphone移植到ipad,所以也許我錯過了代碼中ipad的一些關鍵設置,您能否提供任何線索?謝謝。 – mobguang 2010-10-15 14:54:32

+0

嘗試將webview設置爲類屬性(retain,nonatomic)並將其添加到ib中。在那之後改變它的大小應該更容易。 – 2010-10-15 15:02:05