I’ve got a problem – I’m getting EXC_BAD_ACCESS when trying to set UIWebView.delegate = self;
My code:
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’m commeting delegate string – everything working fine, but I didn’t recieve my webViewDidFinishLoad event.
What I’m doing wrong?
The error isn’t in the code you have posted. Your zombie message is saying your reference to
vkLoginis bad. So you need to look at whatever class creates and holds a reference to yourvkLoginclass.That class should be doing something like a
vkLogin *foo = [[vkLogin alloc] init];Update:
Based on your comments it looks like you are creating a local variable for
vkLogin. It would be most useful to see the code creates and usesvkLoginand how it’s called. Barring that, here are a few guesses.You are called the method which creates and adds
vkLoginto a subView more than once. (Each time would create a new instance).You have some sort of call back which can occur after
vkLoginhas been removed.My guess is
vkLoginshould be apropertyin your class, not a local method variable.in your .h you would add
@proprerty (strong, nonatomic) vkLogin *vk;and in your .m file you could refer to it as
self.vkso you’d create it and add it as a subview like:On a side note, convention says we should start class names with a capital letter, so you’d name the class
VkLoginwhich would make it easily distinguishable from a variable namedvkLogin(but worry about that after you solve the problem)