单视图控制器中的两个表视图:在加载数据之前首先显示视图

时间:2013-08-01 09:40:37

标签: ios tableview

我有一个主视图控制器,它通过一个按钮调用CategoryAndItemController。

我在CategoryAndItemController中有2个UITableViewController。

这里是viewDidLoad方法代码:

if enter code here(categoriesController == nil) {
    categoriesController = [[CFCategoriesTableViewController alloc] init];
}
if (itemsController == nil) {
    itemsController = [[CFItemsTableViewController alloc] init];
}

[categoriesTable setDataSource:categoriesController];
[itemsTable setDataSource:itemsController];

[categoriesTable setDelegate:categoriesController];
[itemsTable setDelegate:itemsController];

categoriesController.view = categoriesController.tableView;
itemsController.view = itemsController.tableView;

我需要的是显示CategoryAndItemController.view然后在该视图中请求数据。

现在,当我按下Button以调用CategoryAndItemController时,视图将仅在获取所有数据后出现,并且在CategoryAndItemController.view出现之前将有2-3秒的时间。

我需要首先显示CategoryAndItemController.view,然后在加载数据时添加一个UIActivityIndi​​catorView。

2 个答案:

答案 0 :(得分:1)

您需要将代码从viewDidLoad转移到viewDidAppear。

在viewDidLoad中添加加载程序。

答案 1 :(得分:0)

在viewDidLoad

中添加此代码
- (void)viewDidLoad
   {

      UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc]   ini

        tWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
                activityIndicator.hidesWhenStopped = YES;
                activityIndicator.hidden = NO;
               activityIndicator.center=  self.view.center
                [activityIndicator startAnimating];
                [self.view addSubview:activityIndicator]

             [self performSelectorInBackground:@selector(call_progress) withObject:nil];
    }

    -(void)call_progress
    {

       // web service code:

       [activityIndicator stopAnimating];
       [activityIndicator removeFromSuperview];

    }
相关问题