本文介绍了异步调用使用IOS 4的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要asynchronically调用一个方法。这是从服务器获取HTML并将它设置为一个方法的UIWebView

I want to call a method asynchronically. It's a method that gets HTML from a server and sets it to a UIWebView:

NSString *htmlTest = [BackendProxy getContent];
[webView loadHTMLString:htmlTest baseURL: nil];
[webView setUserInteractionEnabled:YES];

我想在数据读取开始在的UIWebView 一个活动的指标,所以我需要调用的getContent asynchronically。我怎样才能做到这一点?

I want to start an activity indicator in the UIWebView during the data fetch, so I need to call getContent asynchronically. How can I achieve that?

推荐答案

我建议 performSelectorInBackground:withObject: NSObject的。

这样的:

- (void)loadIntoWebView: (id) dummy
{

    NSString *html = [BackendProxy getContent];
   [self performSelectorOnMainThread: @selector(loadingFinished:) withObject: html];
}


- (void)loadingFinished: (NSString*) html
{
   // stop activity indicator
   [webView loadHTMLString:html baseURL: nil];
   [webView setUserInteractionEnabled:YES];
}

- (void) foo
{
   // ...
   // start activity indicator
   [self performSelectorInBackground: @selector(loadIntoWebView:) withObject: nil];
}

这篇关于异步调用使用IOS 4的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:56