Tableview和MBProgressHUD没有加载对象

时间:2015-07-16 07:46:41

标签: ios objective-c iphone

所以我在TVC中有这段代码

-(void)getCats {
    [HUD showAnimated:YES whileExecutingBlock:^{
        catArray = [menuPost getCategories];
    } completionBlock:^{
        if(catArray == nil){
            [[[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Hubo un problema intente mas tarde" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
        }
    }];
}

我放置了一些断点,我注意到我没有立即执行该方法跳转到

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return catArray.count;
}

所以问题是因为它跳过了这行代码(下面),numberOfRows是0并且这个方法在发帖后返回NSMutableArray它不会显示对象

catArray = [menuPost getCategories];

1 个答案:

答案 0 :(得分:1)

您的代码很好,you are not refresh your table

-(void)getCats {
[HUD showAnimated:YES whileExecutingBlock:^{
    catArray = [menuPost getCategories];
} completionBlock:^{
    if(catArray == nil){
        [[[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Hubo un problema intente mas tarde" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil] show];

  // if your array count ==0 , hidden the table
   [yourtableviewname setHidden:YES];

    }
   else
   {
      // if your array count !=0 , open the table, and reload/refresh the table
     [yourtableviewname setHidden:NO];
    [yourtableviewname reloadData];
  }
}];
}