我有這個問題,我現在正在掙扎幾天。我基本上想要像Instagram一樣製作個人資料。ios在屏幕的一部分顯示視圖和視圖控制器
當你點擊在上面的「標籤欄」前兩個按鈕中的一個內容顯示在下部。屏幕的上半部分保持不變。我有一些UIViewControllers和一些UITableViewController。我有5個按鈕可以顯示視圖控制器。我的問題是,我可以顯示一個tableviewcontroller,但如果我嘗試顯示第二個,然後回到第一個,例如,它卡住了我顯示的最後一個。我希望這很清楚。這裏是顯示viewcontroller的代碼。
- (IBAction)wallButtonPressed:(id)sender
{
if(!_userWallViewController) {
self.userWallViewController = [[WallViewController alloc] init];
self.userWallViewController.activityFeedTableView.bounds = self.containerView.bounds;
}
[self.currentViewController.view removeFromSuperview];
[self.currentViewController removeFromParentViewController];
self.currentViewController = self.userWallViewController;
self.userWallViewController.searchURLString = [NSString stringWithFormat:@"/event/user/%@", self.userID];
self.userWallViewController.containerView = self.containerView;
[self.containerView addSubview:self.userWallViewController.view];
[self addChildViewController:self.userWallViewController];
[self.userWallViewController.view setNeedsDisplay];
[self.userWallViewController viewWillAppear:YES];
}
containerView是一個UIView,它佔用整個屏幕的下半部分。 currentViewController是一個佔位符viewController,userWallViewController是一個UITableViewController。
任何形式的幫助都非常感謝。這是一個真正的竊聽情況。謝謝
這些屬性設置器是否被重寫?在添加到容器之前,您應該明確地設置視圖的框架。 self.currentViewController.view.frame = self.containerView.bounds;還有一些其他提示:小孩vc不需要知道容器。 viewWillAppear,didAppear,willDisappear,didDisappear應該被正確處理,如果明確的話,或者隱式處理(不應該真的影響你的bug,但總的來說確保事情按預期工作)。在添加視圖之前添加子vc。不需要顯式顯示。 – Matt
嘿。我寫了self.currentViewController.view.frame = self.containerView.bounds,因爲當我試圖顯示tableviewcontrollers時,它們將呈現幾乎全屏。此外,最後兩行是爲了查看它是否以任何方式修復了我的錯誤。當然,它沒有。我也嘗試添加視圖之前添加子vc。不工作。用這個幫助我不會沒有噸的謝謝和讚揚:) – alex
您可以嘗試在根控制器上的viewDidLoad中添加視圖和子視圖控制器,然後設置選定的視圖,只隱藏和取消隱藏正確的視圖。你也可以將邏輯分解成另一種方法,以便易於追蹤;該按鈕觸發[self showViewWithIndex:[buttonArray indexOfObject:button]]。在你完成這個工作後,你可以嘗試根據需要去除視圖來進行優化,但這可能是一個更簡單的方法。 – Matt