在 webview 上添加活动指示器
我正在解析 RSS 提要并在网络视图中加载...我想要的是..将自定义活动指示器放置在确切的位置..解析开始的位置和解析结束的位置....下面是代码。
@implementation MenuAndWineListViewController
NSDictionary *dict;
UIAlertView * errorAlert;
- (void)viewDidLoad
{
self.title=@"Menu & WineList";
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
activityIndicator1 = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]autorelease];
activityIndicator1.frame=CGRectMake(0.0,0.0, 40.0, 40.0);
activityIndicator1.center=self.view.center;
[self.view addSubview:activityIndicator1];
NSURL *baseURL=[[NSURL
URLWithString:@"http://www.riverstonechophouse.com.php5-22.dfw1-2.websitetestlink.com /?feedpages&max=0&sort_order=ASC&parent=12&child_of=12"]retain];
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection1=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
if ([stories count] == 0) {
path = @"http://www.riverstonechophouse.com.php5-22.dfw1-2.websitetestlink.com/?feedpages&max=0&
sort_order=ASC&parent=180&child_of=180";
[self parseXMLFileAtURL:path];
}
[menuAndWineListViewController loadHTMLString:[dict objectForKey:@"description"] baseURL:nil];
[menuAndWineListViewController setClipsToBounds:YES];
menuAndWineListViewController.opaque=NO;
menuAndWineListViewController.backgroundColor=[UIColor clearColor];
[menuAndWineListViewController setDelegate:self];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
NSLog(@"found file and started parsing");
}
- (void)parseXMLFileAtURL:(NSString *)URL
{
stories = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"])
{
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"item"])
{
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentSummary forKey:@"description"];
[stories addObject:[item copy]];
}
for (i=0 ; i<stories.count;i++)
{
dict = [stories objectAtIndex:i];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentElement isEqualToString:@"title"])
{
[currentTitle appendString:string];
}
else if ([currentElement isEqualToString:@"description"])
{
[currentSummary appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
[activityIndicator1 stopAnimating];
[activityIndicator1 removeFromSuperview];
NSLog(@"stories array has %d items", [stories count]);
}
i m parsing an rss feed and loading in a webview...wat i want is ..to place a custom activity indicator in the exact place..where the parsing begins and the place where the parsing ends....below is the code.
@implementation MenuAndWineListViewController
NSDictionary *dict;
UIAlertView * errorAlert;
- (void)viewDidLoad
{
self.title=@"Menu & WineList";
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
activityIndicator1 = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]autorelease];
activityIndicator1.frame=CGRectMake(0.0,0.0, 40.0, 40.0);
activityIndicator1.center=self.view.center;
[self.view addSubview:activityIndicator1];
NSURL *baseURL=[[NSURL
URLWithString:@"http://www.riverstonechophouse.com.php5-22.dfw1-2.websitetestlink.com /?feedpages&max=0&sort_order=ASC&parent=12&child_of=12"]retain];
NSURLRequest *request = [NSURLRequest requestWithURL:baseURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
connection1=[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
if ([stories count] == 0) {
path = @"http://www.riverstonechophouse.com.php5-22.dfw1-2.websitetestlink.com/?feedpages&max=0&
sort_order=ASC&parent=180&child_of=180";
[self parseXMLFileAtURL:path];
}
[menuAndWineListViewController loadHTMLString:[dict objectForKey:@"description"] baseURL:nil];
[menuAndWineListViewController setClipsToBounds:YES];
menuAndWineListViewController.opaque=NO;
menuAndWineListViewController.backgroundColor=[UIColor clearColor];
[menuAndWineListViewController setDelegate:self];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
NSLog(@"found file and started parsing");
}
- (void)parseXMLFileAtURL:(NSString *)URL
{
stories = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[rssParser setDelegate:self];
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"item"])
{
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:@"item"])
{
[item setObject:currentTitle forKey:@"title"];
[item setObject:currentSummary forKey:@"description"];
[stories addObject:[item copy]];
}
for (i=0 ; i<stories.count;i++)
{
dict = [stories objectAtIndex:i];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([currentElement isEqualToString:@"title"])
{
[currentTitle appendString:string];
}
else if ([currentElement isEqualToString:@"description"])
{
[currentSummary appendString:string];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
[activityIndicator1 stopAnimating];
[activityIndicator1 removeFromSuperview];
NSLog(@"stories array has %d items", [stories count]);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将
将 放在
parseXMLFileAtURL
方法的开头,将放在
parserDidEndDocument
的开头。像您一样
I'd put the
at the beginning of the
parseXMLFileAtURL
methodand the
at the beginning of the
parserDidEndDocument
like you did.