2012-05-03 31 views
5

我有一個UITableView類,使用以下方法調用加載覆蓋時,轉到下一個屏幕。問題是這個加載屏幕不會隨着列表一起滾動...所以如果你滾動一下並點擊某個東西,加載屏幕就不會顯示(因爲它在頂部)。我怎樣才能讓加載屏幕始終保持在UITableView之上?請知道每個UITableView都包含在UITabBar中包含的UINavBar中。這是我的代碼:覆蓋不滾動與UITableView - iOS

-(void)createLoadScreen 
{ 
    CGRect screenRect = [self.view bounds]; 
    CGRect overlayFrame = CGRectMake(0.0, 0.0, screenRect.size.width, screenRect.size.height); 
    overlay = [[UIView alloc] initWithFrame:overlayFrame]; 
    overlay.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7]; 
    CGRect frame = CGRectMake(screenRect.size.width/2 - 25.0, screenRect.size.height/2 - 70, 25.0, 25.0); 
    loading = [[UIActivityIndicatorView alloc] initWithFrame:frame]; 
    [loading setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    [loading sizeToFit]; 
    loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | 
           UIViewAutoresizingFlexibleRightMargin | 
           UIViewAutoresizingFlexibleTopMargin | 
           UIViewAutoresizingFlexibleBottomMargin); 
    loading.hidesWhenStopped = YES; 
    [overlay addSubview:loading]; 
} 

-(void)showActivityIndicator 
{ 
    [self.view addSubview:overlay]; 
    [loading startAnimating]; 
} 

-(void)removeActivityIndicator { 
    [loading stopAnimating]; 
    [overlay removeFromSuperview]; 
} 

回答

5

你使用的是UITableViewController嗎?

您應該可以通過將疊加視圖添加到表的超級視圖而不是表視圖本身來解決您的問題。這樣你的覆蓋層實際上和你的滾動表視圖分開

-(void)showActivityIndicator 
{ 
    [[self.view superview] addSubview:overlay]; 
    [loading startAnimating]; 
} 
+0

漂亮!感謝的人...... –

+0

其實......現在有些事情正在發生。 uiactivityindicator正在移動位置(高度明智)。不知道爲什麼會發生這種情況,但它似乎隨機更高和更低,這取決於我點擊哪個表格單元格。有任何想法嗎? –

+0

這是我將它添加到uitableview的超級視圖 –