2012-02-29 69 views
0

我在一個UITableView主從aplication showind數據有MasterViewController是不可見的。添加的視圖中MasterViewController直到UITableView的加載數據

數據從網上批量加載,所以當第一次加載數據到達時,我顯示一個UIView下載活動。

雖然沒有數據被裝載在UITableView的活性指示器視圖是不可見的。然後,在加載此數據並且應用持續加載之後,會顯示活動指示器視圖。

我的MasterViewController實現委託方法,以便在下載過程開始時得到通知,並在每批數據結束時收到通知。

  • 爲什麼AEMEventosListDidStartLoadingEventos:加載的UIView(self.downloadingProgrssView)是不可見的第一次調用該方法?

下面是代碼:

-(void)AEMEventosListDidStartLoadingEventos:(AEMEventosList *)evList 
{ 

// The views created here are not displayed the first time this method is called while the UITableView has no data. 
//Once the TableView has been filled the followings calls to this method get the UIView displayed. 

    //Crear una vista con un idicador de progreso. 

    //Ancho y alto de activity Indicator 
    int widthAndHeigth = 30; 
    //Tamaño de activityIndicator 
    CGRect activityViewFrame = CGRectMake(10, 5, 20, 20); 
    //Tamaño de titleView 
    CGRect titleViewFrame = CGRectMake(widthAndHeigth + 20, 0, self.parentViewController.view.frame.size.width - widthAndHeigth, widthAndHeigth); 
    //Tamaño de downloadgingProgressView 
    CGRect downloadingProgressFrame = CGRectMake(0 + 20, self.parentViewController.view.frame.size.height - widthAndHeigth, self.parentViewController.view.frame.size.width - 40, widthAndHeigth + 13); 

    //Leyenda de la ventana. 
    NSString *title; 
    switch (evList.downloadingEventosGroupFlag) { 
     case 0: 
      title = NSLocalizedString(@"Downloading today's events", @"Downloading today's events leyend."); 
      break; 
     case 1: 
      title = NSLocalizedString(@"Downloading events in a week", @"Downloading events in a week leyend."); 
      break; 
     case 2: 
      title = NSLocalizedString(@"Downloading events in a month", @"Downloading events in a month leyend."); 
      break; 
     case 3: 
      title = NSLocalizedString(@"Downloading later events", @"Downloading later events leyend."); 
      break;    
     default: 
      title = @""; 
      break; 
    } 


    UIActivityIndicatorView *acView = [[UIActivityIndicatorView alloc] initWithFrame:activityViewFrame]; 
    acView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite; 
    acView.hidesWhenStopped = NO; 
    acView.tag = kActivityIndicatorViewTag; 
    [acView startAnimating]; 

    UILabel *titleView = [[UILabel alloc] initWithFrame:titleViewFrame]; 
    titleView.text = title; 
    titleView.font = [UIFont systemFontOfSize:11]; 
    titleView.backgroundColor = [UIColor clearColor]; 
    titleView.textColor = [UIColor whiteColor]; 
    titleView.tag = kNameViewTag; 

    UIView *aux = [[UIView alloc] init]; 
    self.downloadingProgressView = aux; 
    [aux release]; 
    self.downloadingProgressView.frame = downloadingProgressFrame; 
    self.downloadingProgressView.backgroundColor = [UIColor colorWithRed:0.3 green:0.4 blue:0.6 alpha:0.9]; 
// self.downloadingProgressView.tag = kDownloadingProgessViewTag;  
    downloadingProgressView.layer.cornerRadius = 13; 

    [self.downloadingProgressView addSubview:acView]; 
    [self.downloadingProgressView addSubview:titleView]; 
    [acView release]; 
    [titleView release]; 

    //Añadir la vista y animar 
    [self.parentViewController.view addSubview:self.downloadingProgressView];  
    [self.downloadingProgressView setFrame:CGRectMake(20.0f, 480.0f, 280.0f, 480.0f)]; //notice this is OFF screen! 
    [UIView beginAnimations:@"animateTableView" context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [self.downloadingProgressView setFrame:downloadingProgressFrame]; //notice this is ON screen! 
    [UIView commitAnimations]; 

} 


-(void)AEMEventosListDidFinishLoadingEventos:(id)evList { 

    //Reasignar ls nueva lista de eventos descargada 
    self.eventosList = evList; 
    //Recargar la tabla 
    [self.tableView reloadData]; 
    //Eliminar la vista de progreso de descarga y animar 
    [UIView beginAnimations:@"animateTableView" context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [self.downloadingProgressView setFrame:CGRectMake(20.0f, 480.0f, 280.0f, 480.0f)]; //notice this is OFF screen 
    [UIView commitAnimations]; 
    self.downloadingProgressView = nil; 
} 


-(void)AEMEventosListDownloadingError:(AEMEventosList *)eventosList withError:(NSError *)error { 

    //Eliminar la vista de progreso de descarga 
    [[self.parentViewController.view viewWithTag:kDownloadingProgessViewTag] removeFromSuperview]; 

    //Log el error 
    NSLog(@"%@", error); 

    //Mostrar un mensaje de error 
    UIAlertView *alertView = [[UIAlertView alloc] 
           initWithTitle:NSLocalizedString(@"Download error", @"Alert View title for download error") 
           message:[error localizedDescription] 
           delegate:nil 
           cancelButtonTitle:@"Ok" 
           otherButtonTitles:nil]; 
    [alertView show]; 
    [alertView release]; 
} 
+0

那麼,問題在哪裏? – NeverBe 2012-02-29 10:09:19

+0

這很明顯,但也許我的英語不清楚。我已經更新了一個明確的問題。 – 2012-02-29 13:08:52

+0

你是否在主線程上更新你的觀點? – NeverBe 2012-02-29 13:58:30

回答

0

的問題是,我開始在AppController中下載過程之前,我在ApplicationDidFinishLaunching加載主視圖。對委託方法的第一次調用是快速的,當我附加視圖時,應用程序的主視圖不顯示。

我只是將代碼移動到applicationdidFinishLaunchingWithOptions方法中的這段代碼之後開始下載,並且所有的東西都開始工作了。

self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease]; 
self.navigationController.toolbarHidden = NO; 
self.window.rootViewController = self.navigationController; 
[self.window makeKeyAndVisible];