0

我的代码在 iOS 7 上运行良好,但在 iOS 6 中崩溃。我的应用程序运行良好,但是当我单击选项卡时出现问题,否则它运行良好。

检查链接:EXC_BAD_ACCESS 虽然切换 tabControllers但没有运气。

下面是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webView = [[UIWebView alloc] init];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[JLTBackgroundHelper getBackgroundImageForView]];
    self.webView.opaque = NO;
    self.webView.backgroundColor = [UIColor clearColor];

    UIViewController *rootVC = [[UIViewController alloc] init];
    rootVC.title = @"Contact JLT Sport";
    rootVC.view = self.webView;
    self.viewControllers = @[rootVC];

    NSString *fileName;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        // iPad-specific
        fileName = @"contact_ipad";
    } else {
        // iPhone-specific
        fileName = @"contact";
    }


    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:fileName ofType:@"html" inDirectory:@"Assets/web"];

    NSURL *url = [NSURL fileURLWithPath:htmlFile];
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
    _webView.delegate= self;


    }

    //send external URL requests to Safari
    - (BOOL) webView:(UIWebView*)wv shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navType
    {
    if (navType == UIWebViewNavigationTypeLinkClicked
        && [request.URL.scheme hasPrefix:@"http"])
    {
        [[UIApplication sharedApplication] openURL:request.URL];
        return NO;
    }
    return YES;
    }
    @end

请指导/建议。

4

1 回答 1

0

尝试这个 :

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webView = [[UIWebView alloc] init];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[JLTBackgroundHelper getBackgroundImageForView]];
   self.webView.opaque = NO;
   self.webView.backgroundColor = [UIColor clearColor];

   UIViewController *rootVC = [[UIViewController alloc] init];
   rootVC.title = @"Contact JLT Sport";
   rootVC.view = self.webView;
   self.viewControllers = @[rootVC];

   NSString *fileName;
   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
      // iPad-specific
      fileName = @"contact_ipad";
  } else {
    // iPhone-specific
    fileName = @"contact";
 }


  NSString *htmlFile = [[NSBundle mainBundle] pathForResource:fileName ofType:@"html" inDirectory:@"Assets/web"];

NSURL *url = [NSURL fileURLWithPath:htmlFile];
NSURLRequest *request =[NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
self.webView.delegate= self;

}
if above solution does not work then try this:

Debug with Instrument 

Go to Product >> Profile >> All > Zoombies 

Press "Record" button on top left corner 

Perform your task and when application get EXC_BAD_ACCESS the instrument give that    line where the application was being crash.

Also debug in this method to:[JLTBackgroundHelper getBackgroundImageForView];

 **Make sure that all variable is being  get memory before use it.**

  May be the resin is that some method is depreciated in iOS 7.

 These are the possible scenario of application is being crash and its  solution.
于 2013-11-11T09:42:18.583 回答