-2

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

在向用户显示该数据后,该表轮询 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 服务响应时更新表格?

4

2 回答 2

1

使用-[UIViewController viewDidAppear:]

于 2013-09-14T02:35:40.930 回答
0

好吧,简短的回答是[tableView reloadData],但是您的问题非常含糊。

于 2013-09-14T02:30:32.417 回答