gpt4 book ai didi

objective-c - UIWebView 委托(delegate)中的 EXC_BAD_ACCESS

转载 作者:可可西里 更新时间:2023-11-01 05:37:43 25 4
gpt4 key购买 nike

我有一个问题 - 我在尝试设置 UIWebView.delegate = self 时收到 EXC_BAD_ACCESS;

我的代码:

vk登录.h -

#import UIKit/UIKit.h

@interface vkLogin : UIViewController <UIWebViewDelegate>
{
UIWebView *authBrowser;
UIActivityIndicatorView *activityIndicator;
}

@property (nonatomic, retain) UIWebView *authBrowser;
@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;

@end

vk登录.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

因此,如果我正在提交委托(delegate)字符串 - 一切正常,但我没有收到我的 webViewDidFinishLoad 事件。

我做错了什么?

最佳答案

错误不在您发布的代码中。你的僵尸消息说你引用了 vkLogin不好。因此,您需要查看创建并持有对您的 vkLogin 的引用的任何类。类。

那个类应该做类似 vkLogin *foo = [[vkLogin alloc] init]; 的事情

更新:

根据您的评论,您似乎正在为 vkLogin 创建局部变量.查看代码创建和使用 vkLogin 将是最有用的以及它的名字。除此之外,这里有一些猜测。

你被称为创建和添加的方法vkLogin不止一次到 subview 。 (每次都会创建一个新实例)。您有某种回调可能发生在 vkLogin 之后已被删除。

我猜是 vkLogin应该是 property在您的类中,而不是本地方法变量。

在你的.h中你会添加 @proprerty (strong, nonatomic) vkLogin *vk;

在您的 .m 文件中,您可以将其称为 self.vk所以你会创建它并将其添加为 subview ,如:

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

顺便说一句,惯例说我们应该以大写字母开头类名,因此您将类命名为 VkLogin这将使它很容易与名为 vkLogin 的变量区分开来(但是解决了问题之后再担心)

关于objective-c - UIWebView 委托(delegate)中的 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12302536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com