0

我有uipopovercontroller有uitableview,我想在uitableview方法的didselectrowatindexpath方法中開始動畫uiactivityindicatorview。這是我的代碼。uiactivityindicatorview不工作在uipopoverviewcontroller iphone

-(IBAction)btnA_Clicked:(id)sender{ 

    self.objuiviewCon = [[myuiviewController alloc] initWithNibName:@"myuiviewController" bundle:nil]; 
    [self.objuiviewCon setDelegate:self]; 

    self.ObjApopCon = [[UIPopoverController alloc] initWithContentViewController:self.objuiviewCon]; 
    [self.ObjApopCon setPopoverContentSize:CGSizeMake(self.objuiviewCon.view.frame.size.width, self.objuiviewCon.view.frame.size.height)]; 
    [self.ObjApopCon presentPopoverFromBarButtonItem:btnA permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

} 

@interface myuiviewController : UIViewController<UITableViewDelegate,UITableViewDataSource>{ 

IBOutlet UITableView *tblList; 

IBOutlet UIActivityIndicatorView *actiIndi; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [myarr count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    NSLog(@"cell called"); 

    cell.textLabel.text = [myarr objectAtIndex:indexPath.row]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"didSelectRowAtIndexPath called"); 
    [actiIndi startAnimating]; 
} 

所有在接口構建器和委託中連接的iboutle也被設置。但我的問題是我的didSelectRowAtIndexPath方法正在調用,但activityindicator不是動畫。

我打電話webservice時,通過使用協議點擊表視圖行,所以我需要uiactivityindicatorview動畫,直到得到webservice的輸出。

任何建議將不勝感激。

回答

0

檢查活動和表的視圖可能是UIActivityIndi​​cator是在UITableView的後面。 而且還要檢查它沒有被隱藏

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"didSelectRowAtIndexPath called"); 
    [tableview bringSubviewToFront:actiIndi]; 
    [actiIndi startAnimating]; 
} 
+0

謝謝Cocoa Matters for answering.it將桌面帶到前臺。所以actiIndi不會顯示。 – 2012-07-18 05:24:06

0

對於你說的話,也有一些didSelectRowAtIndexPath方法更多的代碼:。也就是說,您從那裏調用的方法調用webservice。

我認爲所有的問題是你正在同步調用web服務。您必須記住,用戶界面中的每個更改都只在您的方法完成後才起作用。因此,如果您沒有將控制權返回到主界面循環,startAnimating將不會執行任何操作。

解決的辦法是,當你調用調用Web服務的方法,而不是這樣的:

[actiIndi startAnimating]; 
[self callWebservice:fooObject]; 

這樣寫:

[actiIndi startAnimating]; 
[self performSelector:@selector(callWebservice:) withObject:fooObject afterDelay:0.0]; 

,那麼你將控制返回到主循環中,活動指示器將開始旋轉,然後儘快調用另一種方法。

+0

謝謝你回答Gabriel。實際上,我已經把Web服務調用置於評論中,並嘗試對動畫指標進行動畫處理,但它仍不具有動畫效果。 – 2012-07-18 05:28:27

+0

您可以編輯您的答案幷包含該代碼嗎? – Gabriel 2012-07-18 08:55:33

+0

我已將所有代碼置於評論中。我的代碼只包含以下內容。 NSLog(@「didSelectRowAtIndexPath called」); [actiIndi startAnimating]; – 2012-07-18 09:14:25