UIWebView委托中的EXC_BAD_ACCESS
问题描述:
我遇到了一个问题 - 在试图设置UIWebView.delegate = self时,我得到了EXC_BAD_ACCESS;UIWebView委托中的EXC_BAD_ACCESS
我的代码:
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
所以,如果我commeting委托串 - 一切工作正常,但我没有收不到我的webViewDidFinishLoad事件。
我在做什么错了?
答
错误不在您发布的代码中。你的僵尸消息是说你对vkLogin
的引用不好。所以你需要看看什么课程创建,并持有对你的课程的参考。
该类应该做的像vkLogin *foo = [[vkLogin alloc] init];
更新的东西:
根据您的意见,它看起来像你的vkLogin
创建一个局部变量。看到代码创建并使用vkLogin
以及它的调用方式是非常有用的。除了这个,这里有一些猜测。
您被称为创建并不止一次地向子视图添加vkLogin
的方法。 (每次都会创建一个新实例)。 您在删除vkLogin
后会发生某种回拨。
我的猜测是vkLogin
应该是你的类中的property
,而不是本地方法变量。
你想补充 @proprerty (strong, nonatomic) vkLogin *vk;
,并在您.m文件,你可以把它称为self.vk
所以你创建它,并把它添加像一个子视图:
self.vk = [[vkLogin alloc] init];
[self.view addSubview:self.vk];
在附注中,约定表示我们应该使用大写字母开始类名,所以您可以命名类VkLogin
,这可以使它很容易与名为vkLogin
的变量区分开来(但是在解决问题后会担心)
除了问题之外,恭喜你成为100,000个客观标记问题! – TheAmateurProgrammer
以这种方式指定'authlink'并重试:'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“;' – Adam
我建议编辑你的方案并打开僵尸对象。它很可能提供有关错误访问内容的更好信息。 –