我的代码适用于iOS 7,但在iOS 6中崩溃。我的应用程序工作正常但是当我点击选项卡时问题就出现了,否则它工作正常。
检查链接:EXC_BAD_ACCESS While switching 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
请指导/建议。
答案 0 :(得分: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.