加载UITableViewController

web-services加载数据,然后插入到UITableViewController中。

我已经实现了,就是有一个小问题,在转入UITableViewController之前会在第一个UIView中停留一会儿。如果网速慢的话会停留很长时间。

能不能显示空的UITableViewController,用loading标志代替?然后只显示从web-services提取数据,重载table。

调用web-services函数:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self._completeList = [ [NSMutableArray alloc]init];
    self._completeList = [self getListFromWebServices];
}

最好的方法就是使用 Grand Central Dispatch (GCD)

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
   //code for webservices calling
    dispatch_async(dispatch_get_main_queue(), ^{
       //reload you tableview here
       [self.tableview reloadData];
    });
});

最简单的方法是删除这两行代码 into -(void)viewDidAppear:

- (void)viewDidLoad {
  [super viewDidLoad];
  self._completeList = [[NSMutableArray alloc]init];
}
- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated]; 
  self._completeList = [self getListFromWebServices];
  // Assuming that [self getListFromWebServices] is a blocking call.
  [self.tableView reloadData];
}

但是我建议使用 GCD:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) { 
      _completeList = [[NSMutableArray alloc] init];
      dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self._completeList = [self getListFromWebServices];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
      });
    }
    return self;
}