2009-11-10 73 views
1

我使用NSObject類inwhich我有NSURLConnection的,但我怎麼能顯示UIActivityIndi​​catorView當連接建立和成品.....?我在appdelegate.m文件試圖 inwhich我appdidfnish方法都提到會顯示NSObject顯示UIActivityIndi​​catorView?

Search = [[UIActivityIndicatorView alloc] 
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    [Search setCenter:CGPointMake(160, 240)]; 
    [window addSubview: Search]; 

而且我有喜歡

 -(void)anim 
{ 
    [search startAnimating]; 
} 

個體的方法,但如果我叫過的appdelegate對象這種方法在NSobject.m頁面時,它會不會工作。 我有什麼做的?任何幫助?請?

回答

0

我不確定,但你在哪裏設置activityIndi​​catorView的框架?我剛剛試過這段代碼,它的工作原理非常完美。

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

}

+0

正常,如果我們像聲明如下它在視圖控制器... 搜索= [[ UIActivityIndi​​catorView alloc] initWithActivityIndi​​catorStyle:UIAc tivityIndi​​catorViewStyleWhiteLarge]; [Search setCenter:CGPointMake(160,240)]; [window addSubview:Search]; - (void)anim { [search startAnimating]; } – 2009-11-10 10:52:18

+0

但我不能停止其他方法,如[activityIndi​​cator startAnimating]; 因爲它被聲明爲局部變量 – 2009-11-10 11:25:44

相關問題