gpt4 book ai didi

objective-c - 在 webview 上添加事件指示器

转载 作者:行者123 更新时间:2023-11-29 05:04:05 25 4
gpt4 key购买 nike

我正在解析 RSS 提要并在 Web View 中加载...我想要的是..将自定义事件指示器放置在解析开始的确切位置...以及解析结束的位置...下面是代码。

@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]);
}

最佳答案

我会把

[activityIndicator1 startAnimating];

parseXMLFileAtURL 方法的开头

[activityIndicator1 stopanimating];

像您一样在parserDidEndDocument的开头。

关于objective-c - 在 webview 上添加事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6054667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com