活动指标不隐藏

时间:2015-12-19 18:24:41

标签: ios objective-c uitableview uiactivityindicatorview

我想使用活动指示器来显示加载活动,如下所示:

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //Create cell

    static NSString *cellIdentifier = @"cell";

    MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCellView" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    // Check condition, either we got objects

    if (!isDataLoaded){

        cell.myActivityIndicator = [[UIActivityIndicatorView alloc]
                        initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

        cell.myActivityIndicator.center=self.view.center;
        [cell.myActivityIndicator startAnimating];
        [self.view addSubview:cell.myActivityIndicator];

        NSLog(@"Current loading");

    }   else {

        cell.myActivityIndicator.hidden = YES;
        [cell.myActivityIndicator removeFromSuperview];

    }


    return cell;
}

然而,即使我知道“else”块被执行,它也不会消失。如何隐藏它?

0 个答案:

没有答案