当tableviewcontroller完成加载数据并出现时调用方法

时间:2013-09-14 02:23:13

标签: ios uitableview

我正在尝试构建一个表视图控制器,在查看数据库时从数据库加载数据。

在向用户显示该数据后,该表轮询Web服务以获取更新,同时数据对用户可见,并在Web服务响应时重新加载。

这是控制器:

- (void) viewDidAppear:(BOOL)animated
{
    NSLog(@"in view did appear");
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:@"menuView" bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
}
return self;


}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
   [super viewDidLoad];

   // make space between the start of the screen and the start of th table
   [self.tableView setContentInset:UIEdgeInsetsMake(80,0,0,0)];


   // connect to database
   database = [[connectToDB alloc] init];
   [database setDelegate:self];


   // fill the table from the DB
   [database selectSqlQuere:@"SELECT * FROM ZTASKS"];


   // refresh when table scroll down
   UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
   [refreshControl addTarget:self action:@selector(refresh:)     forControlEvents:UIControlEventValueChanged];
 [self.tableView addSubview:refreshControl];

 }
- (void)didReceiveMemoryWarning
 {
  [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

 #pragma mark - Table view data source


 @end

如何在轮询Web服务时让用户看到该表,并在Web服务响应时更新表?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

嗯,简短的回答是[tableView reloadData],但你的问题非常模糊。