EXC_BAD_ACCESS in the UIWebView delegate

I have a problem: I get EXC_BAD_ACCESS when I try to set UIWebView.delegate = self;

My code is:

vkLogin.h -

#import UIKit/UIKit.h @interface vkLogin : UIViewController <UIWebViewDelegate> { UIWebView *authBrowser; UIActivityIndicatorView *activityIndicator; } @property (nonatomic, retain) UIWebView *authBrowser; @property (nonatomic, retain) UIActivityIndicatorView *activityIndicator; @end 

vkLogin.m -

 #import "vkLogin.h" #import "bteamViewController.h" @implementation vkLogin @synthesize authBrowser; - (void) viewDidLoad { [super viewDidLoad]; activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; activityIndicator.center = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2); activityIndicator.autoresizesSubviews = YES; activityIndicator.hidesWhenStopped = YES; [self.view addSubview: activityIndicator]; [activityIndicator startAnimating]; authBrowser = [[UIWebView alloc] initWithFrame:self.view.bounds]; authBrowser.delegate = self; authBrowser.scalesPageToFit = YES; [self.view addSubview:authBrowser]; NSString *authLink = @"http://api.vk.com/oauth/authorize?client_id=-&scope=audio&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token"; NSURL *url = [NSURL URLWithString:authLink]; [authBrowser loadRequest:[NSURLRequest requestWithURL:url]]; } - (void) webViewDidFinishLoad:(UIWebView *)authBrowser { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Lol" message:@"OLOLO" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil]; [alert show]; } @end 

So, if I am going to delegate a string - everything works fine, but I did not receive the webViewDidFinishLoad event.

What am I doing wrong?

+4
source share
1 answer

Error in the code you posted. Your zombie post says your vkLogin link is bad. Therefore, you need to look at which class creates and contains a reference to your vkLogin class.

This class should do something like vkLogin *foo = [[vkLogin alloc] init];

Update:

Based on your comments, it looks like you are creating a local variable for vkLogin . It would be very helpful to see what code creates and uses vkLogin and what it is called. Considering this, here are a few guesses.

You call a method that creates and adds vkLogin to a subView more than once. (Each time will create a new instance). You have some kind of callback that can happen after uninstalling vkLogin .

My guess is vkLogin should be a property in your class, not a local method variable.

in your .h you would @proprerty (strong, nonatomic) vkLogin *vk;

and in your .m file you can refer to it as self.vk so that you create it and add it as a subtitle, for example:

 self.vk = [[vkLogin alloc] init]; [self.view addSubview:self.vk]; 

The note to the agreement says that we must start the class names with a capital letter, so you would name the class vkLogin , which would be easily distinguishable with a variable called vkLogin (but worry about it after you solve the problem)

+5
source

Source: https://habr.com/ru/post/1432744/


All Articles