我想在单击 UIButton 时添加一个活动指示器并继续为其设置动画,直到加载来自服务 url 的数据。如果加载,则它移动到下一个视图。但我无法这样做..
这是我的代码..
-(IBAction)switchtoGetProviders
{
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(225, 115, 30, 30)];
[activity setBackgroundColor:[UIColor clearColor]];
[activity setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:activity];
[activity release];
[activity startAnimating];
NSURL *urlString= [NSString stringWithFormat:@"http://www.something.net/service.svc/Xml"];
if(arr.count>0)
{
[activity stopAnimating];
ViewController2 *gp=[ViewController2 alloc];
[self presentModalViewController:gp animated:NO];
[gp release];
}
else
{
UIAlertView *alert = [[[UIAlertView alloc]initWithTitle: @"Results not found"
message: @""
delegate: self
cancelButtonTitle:@"OK"
otherButtonTitles:nil]autorelease];
[alert show];
}
}
实际上,当 arr 为空时,我会得到一个alertView
. 出现时alertView
然后activityindicator
开始。当我点击确定按钮时,alertView
它会停止动画。但我希望它在被触摸时立即开始。UIbutton
我该怎么做?我哪里错了?