0
votes

I have uipopovercontroller having uitableview and i want to start animating uiactivityindicatorview in didselectrowatindexpath method of uitableview method. here is my code.

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

all iboutle connected in interface builder and delegate are also set. but my problem is my didSelectRowAtIndexPath method is calling but activityindicator is not animating.

i am calling webservice when click on table view row by using protocol so i need uiactivityindicatorview to animated till get the output of webservice.

any suggestions will be appreciated.

2

2 Answers

0
votes

For what you are saying, there are some more code in didSelectRowAtIndexPath:. That is, you are calling webservice from a method invoked there.

I think all the problem is you are calling webservice synchronously. You have to take in mind that every change in the user interface only works after your methods finish. So, startAnimating will do nothing if you are not returning control to the main interface loop.

The solution is, when you invoke the method that calls webservice, instead of this:

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

write this:

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

then you are returning control to main loop, the activity indicator will start spinning and then, as soon as possible, the other method will be called.

0
votes

Check the View of activity and table may be UIActivityIndicator is behind the UITableView. And also check it's not be hidden

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