我想重新签名包含活动指标的UIAlertView。我正在下面的代码。它在加载数据时正在工作,但UIalertview在成功解析后没有重新签名。我应该在这里给出什么条件?
- (void) updateFilterProgress{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Loading..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
[pool release];
}
在我的按钮点击事件中,我输入以下代码
// **EDIT==1**
[NSThread detachNewThreadSelector:@selector(updateFilterProgress) toTarget:self withObject:nil];toTarget:self withObject:nil]; //for calling updateFilterProgress
NSString *url = [NSString stringWithFormat:@"http://....url...../hespdirectory/phpsqlsearch_genxml.php?lat=%f&radius=%f&lng=%f",lati,longi,radius];
//NSLog(@"NSString *url");
NSLog(@"%@", url);
//NSString *escapedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
{ **//EDIT==2**
[alert dismissWithClickedButtonIndex:0 animated:YES]; //for resigning alertview
for (int i = 0; i < [appDelegate.markers count]; i++)
{
//marker *aMarker = [[marker alloc] init];
marker *aMarker = [appDelegate.markers objectAtIndex:i];
location.latitude = [aMarker.lat floatValue];
location.longitude =[aMarker.lng floatValue];
AddressAnnotation *annobj = [[AddressAnnotation alloc] initWithCoordinate:location];
annobj.title = aMarker.name;
[mapView addAnnotation:annobj];
[annobj release];
}
}
我想重新签名这个包含活动指示符的UIAlertView .......
答案 0 :(得分:1)
将UIAlertView和ActivityIndicator(以及警报视图中的所有对象)设置为类文件的成员。
然后,您通常会释放这些项目(以及您要解除警报的位置),您可以这样称呼:
[myAlertView dismissWithClickedButtonIndex:0 animated:YES];
这与用户单击其上的取消按钮具有相同的效果,这是完全可以接受的。
希望这有帮助!