我使用NSobject类,其中我有NSURLConnection,但是如何在连接建立和完成时显示UIActivityIndicatorView?我尝试过 在appdelegate.m文件中,我在appdidfnish方法中提到了
Search = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[Search setCenter:CGPointMake(160, 240)];
[window addSubview: Search];
我也有个别方法,如
-(void)anim
{
[search startAnimating];
}
但如果我通过NSobject.m页面中的appdelegate对象调用此方法,它将无法工作.. 我该怎么办?任何帮助?请?
答案 0 :(得分:0)
我不确定,但是你在哪里设置activityIndicatorView的框架?我刚刚尝试了这段代码,它的工作非常完美。
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; [activityIndicator setCenter:CGPointMake(160, 240)]; [activityIndicator startAnimating]; [window addSubview:activityIndicator]; UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setFrame:CGRectMake(100, 300, 120, 50)]; [button setTitle:@"press me" forState:UIControlStateNormal]; [button addTarget:self action:@selector(onBtnClk) forControlEvents:UIControlEventTouchUpInside]; [window addSubview:button]; [window makeKeyAndVisible];
这是onBtnClk方法
- (void) onBtnClk{ if([activityIndicator isAnimating]){ [activityIndicator stopAnimating]; }else{ [activityIndicator startAnimating]; }
}