views:

48

answers:

1

Hello everyone,

I used following code to initialize instance of 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;
}

It is very strange, above code is work on iphone simulator, but it will crash on ipad simulator. My xcode is 3.2.4. Could you please kindly provide any clue? Thanks in advance!

Crash log:

#0 0x031b5574 in flushCaches
#1 0x031b38fc in remethodizeClass
#2 0x031b60ea in _read_images
#3 0x031c3784 in map_images_nolock
#4 0x031b5724 in map_images
#5 0x8fe03f2d in _dyld_ZN4dyldL18notifyBatchPartialE17dyld_image_statesbPFPKcS0_jPK15dyld_image_infoE
#6 0x8fe0decd in _dyld_ZN11ImageLoader4linkERKNS_11LinkContextEbbRKNS_10RPathChainE
#7 0x8fe056af in _dyld_ZN4dyld4linkEP11ImageLoaderbRKNS0_10RPathChainE
#8 0x8fe0b242 in __dyld_dlopen
#9 0x9754a868 in dlopen
#10 0x0063b8e6 in initWebUILocalStorageSupport
#11 0x0063a0d6 in -[UIWebView _webViewCommonInit:]
#12 0x0063abfd in -[UIWebView initWithFrame:]
#13 0x0002c467 in -[WebViewController viewDidLoad] at 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 _startDeferredTransitionIfNeeded]
#20 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 CFRunLoopRunInMode
#39 0x034d089d in GSEventRunModal
#40 0x034d0962 in GSEventRun
#41 0x00498372 in UIApplicationMain
#42 0x00002dd8 in main at main.m:14

A: 

Did you change something the WebView initWithFrame? It's not the webview's fault, that is the correct way to create it with a frame. Could you post the rest of the Controller?

inovaction
@inovaction, I just found AutorotateToInterfaceOrientation method will be called firstly, then viewDidLoad method will be called during controller initialization. Do you think any setting I missed for the ipad specified requirement for auto rotation? Thanks.
mobguang
I removed AutorotateToInterfaceOrientation method, then webView could be created without crash. I just want to port my app from iphone to ipad, so maybe I missing some critical setting for the ipad in code, could you please provide any clue? Thanks.
mobguang
Try to put webview as class property (retain, nonatomic) and add it in the ib. It should be easier just to change it's size after that.
inovaction
Hello, how did it go? Managed to make it work?
inovaction