Web サイトをナビゲートするワークフローを作成しています。ワークフローのすべてのステップで 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;
}