【问题标题】:Added View in MasterViewController is not visible until the UITableView is loaded with data在 UITableView 加载数据之前,MasterViewController 中添加的视图不可见
【发布时间】:2012-03-11 02:01:32
【问题描述】:

我在 MAster Detail 应用程序中有一个 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];
}

【问题讨论】:

  • 虽然很清楚,但也许我的英语不清楚。我更新了一个明确的问题。
  • 你更新你对主线程的看法了吗?

标签: ios uitableview


【解决方案1】:

问题是我在加载ApplicationDidFinishLaunching 中的主视图之前在appController 中启动了下载过程。对委托方法的第一次调用是快速的,当我附加视图时,应用程序的主视图没有显示。

我只是在applicationdidFinishLaunchingWithOptions 方法中的此代码之后移动代码以开始下载,一切都开始正常工作。

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

【讨论】:

    猜你喜欢
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2019-05-18
    • 2017-05-19
    相关资源
    最近更新 更多