[英]tableView: didSelectRowAtIndexPath: looks awful if not setting the next viewcontroller's background color
當我嘗試使用tableView: didSelectRowAtIndexPath:
方法推送視圖控制器時,過渡確實可以正常工作,但是其動畫效果看起來非常糟糕; 當我點擊UITableView中的任何單元格時,整個屏幕的三分之一首先變黑(但其他三分之二仍然是原始屏幕的UITableViewCell!),並稍有延遲,整個屏幕變黑了。
我不知道為什么tableView: didSelectRowAtIndexPath:
方法在用戶界面方面如此糟糕。 這是我進行過渡的代碼:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detailViewController = [[DetailViewController alloc] init];
People *people = [_fetchedResultsController objectAtIndexPath:indexPath];
detailViewController.title = people.type1;
[self.navigationController pushViewController:detailViewController animated:YES];
}
但是,如果我將animated:
更改為NO
,則過渡不會有任何問題(就UI而言,再次;這就是我在這里要問的),但是它會立即更改為新的視圖控制器(自然,因為它是動畫處理的內容:首先是NO)。
解決此奇怪行為的方法是,在執行pushViewController: animated:
方法之前,先設置第二個視圖控制器的backgroundColor
,如本問題所示 。
我不知道為什么要在進行過渡之前先設置背景色,為什么要設置其背景色才能解決與UI相關的問題。
我使用iOS 7和Xcode 5。
新viewController的默認背景顏色是透明的,因此當您進行動畫推送時,您可以臨時查看新viewController,因為它會將自身推送到導航堆棧的頂部。
設置不透明的背景色將意味着您的新VC不透明,因此您將無法看到它到下面的VC。
但是,我建議您在新的viewcontroller的viewDidLoad
中設置backgroundColor
,而不是在進行演示的那一類中設置(實際上,呈現viewController並不負責這樣做)。
嘗試在init
方法中設置詳細信息視圖的背景色嗎?
[[self view] setBackgroundColor:[UIColor whiteColor]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.