我正在创建一个工作流来浏览网站,工作流的每一步都必须加载 n 帧,然后知道它准备好了(我必须实现超时)。
我不明白为什么 [self next] 给我这个错误: * -[WebWorkflow next]: message sent to deallocated instance 0x105796ef0
考虑到这个委托函数:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
frameCounter++;
NSInteger frames = [(WebWorkflowStep *)[steps objectAtIndex:index] frames];
NSLog(@"Frame counter %ld of %ld", frameCounter, frames);
[self next];
}
下一个方法:
-(void) next
{
if ( index < [steps count])
{
frameCounter = 0;
index = index + 1;
WebWorkflowStep *step = [steps objectAtIndex:index-1];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:step forKey:@"selector"];
[[NSNotificationCenter defaultCenter] postNotificationName:EVENT_WORKFLOW_NEXT object:nil userInfo:userInfo];
}
}
笔记:
- WebWorflow aka 'self' 已由另一个强大的类创建/绑定
像这样:
@interface AController : NSObject <APIProtocol>
{
WebView *webview;
NSMutableArray *accounts;
WebWorkflow *workflow;
}
@property (strong) WebWorkflow *workflow;
...
我确实创建了这样的工作流程:
workflow = [[WebWorkflow alloc] initWithWebView:webview];
NSArray *getPicturesWorkflow = [NSArray arrayWithObjects:
[[WebWorkflowStep alloc] initWithSelector:@"open" andLoadFrames:0],
[[WebWorkflowStep alloc] initWithSelector:@"login" andLoadFrames:2],
[[WebWorkflowStep alloc] initWithSelector:@"getPictures" andLoadFrames:8],
nil];
[workflow setSteps:getPicturesWorkflow];
它被初始化为:
-(id)initWithWebView:(WebView *)webview
{
self = [ super init];
if(self) {
timeout = 10;
index = 0;
web = webview;
frameCounter = 0;
[web setFrameLoadDelegate:self];
}
return self;
}