0

现在我的项目自动重新加载(在此站点上的某人的帮助下:D)我怎么能得到另一个但停止重新加载?这就是我所拥有的:

-(IBAction)SendGPSData:(id)sender {
    NSURL *myURL =[NSURL URLWithString:@"http://www.google.co.uk"];//<<change this!!!
    NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
    [myWebView2 loadRequest:myRequest];
        [myWebView2 reload];
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(WebViewLoad:) userInfo:nil repeats:YES];

}

-(IBAction)stop:(id)sender {

//what do i put here to stop it reloading?

}

-(void)WebViewLoad:(NSTimer *)theTimer
{
    [myWebView2 reload];

} 

不喜欢这么快问另一个问题,但我是 Xcode 的初学者,所以任何帮助都会很棒:)

Iv 尝试了 myWebView 停止加载;但原来的似乎覆盖了这个:(

4

2 回答 2

0

你可以这样停止:

-(IBAction)stop:(id)sender {

[webView stopLoading];

}
于 2013-01-17T12:54:03.297 回答
0

您还需要停止计时器。所以你也是:

NSTimer* reloadTimer;  // Put this in your class.

reloadTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(WebViewLoad:) userInfo:nil repeats:YES];


-(IBAction)stop:(id)sender
{
    [reloadTimer invalidate];
    reloadTimer = nil;   // Prevents crash, when this method is called twice:
                         // reloadTimer is released when you call invalidate,
                         // so next time invalidate would be called on non-existing
                         // object -> crash.

    [myWebView2 stopLoading];
}

将启动/创建计时器的代码放在单独的方法中可能是有意义的,这样您就可以使用它重新启动重新加载。

于 2013-01-17T13:37:59.257 回答