2015-04-18 81 views
1

我有我的表令人耳目一新內容UIActivityIndi​​catorView以上,它在視圖中居中,像這樣:UIActivityIndi​​catorView浮動一個UITableView

//Start activity indicator 
     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
     indicator.center=self.view.center; 
     CGRect frame = indicator.frame; 
     frame.origin.x = (self.view.frame.size.width/2 - frame.size.width/2); 
     frame.origin.y = (self.view.frame.size.height/2 - frame.size.height/2)-self.navigationController.navigationBar.frame.size.height-20; 
     indicator.frame = frame; 
     [self.view addSubview:indicator]; 
     [indicator startAnimating]; 

但是它與表滾動的那一刻,是有可能得到它漂浮在桌子上方,以便在用戶滾動時保持居中狀態?我試圖將它添加到表超視圖,但沒有奏效。任何指針將非常感激!感謝

+0

什麼表上海華?你在使用表格視圖控制器嗎?導航欄是否適合您? – Wain

+0

嘗試bringsubViewtofront加入之後,查看 –

+0

@Wain我之前使用的導航欄中爲它從來沒有考慮過。難以實現嗎? – KexAri

回答

3

這聽起來像你使用UITableViewController如果是這樣的話,我會建議使用UIViewController來代替。這將使你在你UITableView的頂部添加UIView牽你UIActivityIndicatorView你也可以要輕鬆地攤開來的故事板,它位置的能力,它不會與臺滾動移動,因爲它是這是自己的看法。作爲一般規則,我儘量不要使用UITableViewController,因爲它在這種情況下限制了你。

+0

感謝這個節目,嘗試其他方法,似乎這將是唯一的出路。我想我將來會遠離UITableVIew控制器。它是否比具有表格的標準UIVIewController有什麼優勢? – KexAri

+0

@KexAri沒有,'UITableViewController'從'UIViewController'得到繼承這樣你就不會失去什麼,其實你獲得更多的靈活性。我很早就學會了這一點,當時我也陷入困境,然後不得不重做我的桌面視圖...... – rmp

+1

是的,你失去了很多功能。所有的UITableViewController都會阻止你手動連接數據源和委託。 – KexAri

0

您可以將指標添加到您的tableView的超級看法,但如果它不工作了,你還可以添加應用程序的一個UIWindow的活動的指標。以下是代碼:

UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; // this gives you the current window of the application. 
[keyWindow addSubview:indicator]; // add the indicator on the window. 

一旦工作完成後,通過使用

[indicator removeFromSuperView]; 
indicator = nil; 
除去從窗口活動的指標
+0

我想這一點,沒有錯誤消息,但該指標只是沒有在所有 – KexAri

1
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] 
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 
    spinner.center = CGPointMake(160, 240); 
    spinner.hidesWhenStopped = YES; 
    [self.view addSubview:spinner]; 
    [spinner startAnimating 

];

3

您只需通過非常相似的代碼中添加子視圖創建視圖「頂部」任何的tableview,導航控制器或任何其他的添加任何類型的視圖,但正確的根視圖。只是讓你清楚地確定所需的根視圖。

例如,下面是我實現我的子視圖我的導航控制器的頂在我的應用程序之一:

... 
[self.navigationController.view addSubview:indicator]; 
... 
+0

這是一個優秀的技巧,與UITableViewController一起使用並且可以通過編程方式添加約束。只需在約束中使用navigationcontroller.view,它就可以工作! –

相關問題