我使用自己的标签栏布局开发了自定义UITabbarController
。我有一组UIViewController
,我从这样的stroryboard实例化:
class func instantiateMainViewControllers () -> Array<UIViewController>
{
var controllersArray = Array<UIViewController>()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let feedVC = storyboard.instantiateViewControllerWithIdentifier(BL_UIConst.kFeedControllerIdentifier)
controllersArray.append(feedVC)
let exploreVC = storyboard.instantiateViewControllerWithIdentifier(BL_UIConst.kExploreControllerIdentifier)
controllersArray.append(exploreVC)
let cameraVC = storyboard.instantiateViewControllerWithIdentifier(BL_UIConst.kCameraControllerIdentifier)
controllersArray.append(cameraVC)
let chatVC = storyboard.instantiateViewControllerWithIdentifier(BL_UIConst.kChatControllerIdentifier)
controllersArray.append(chatVC)
let profileVC = storyboard.instantiateViewControllerWithIdentifier(BL_UIConst.kProfileControllerIdentifier)
controllersArray.append(profileVC)
return controllersArray
}
然后分配给我的自定义UITabbarController
的视图控制器数组。在控制器之间切换的工作方式如下(自定义tabbar控制器上有presentationView UIView
以显示子控制器):
private func displayViewController ( atIndex index : Int ) -> Void
{
let controller = viewControllersArray[index]
if ( presentationView.subviews.count > 0 )
{
let presentedView = presentationView.subviews[0]
for ( var i = 0 ; i < viewControllersArray.count ; i++ )
{
let localController = viewControllersArray[i]
if ( localController.view == presentedView )
{
localController.willMoveToParentViewController(nil)
localController.view.removeFromSuperview()
localController.removeFromParentViewController()
break
}
}
}
self.addChildViewController(controller)
controller.view.bounds = self.presentationView.bounds
controller.view.frame = CGRectMake(0.0, 0.0, presentationView.frame.size.width, presentationView.frame.size.height - 10)
presentationView.addSubview(controller.view)
}
我在viewDidAppear
函数进行控制器数组的初始设置(选择第一个并调用displayViewController过程)。第一个控制器是表格视图。
发生了一件非常神奇的事情。在模拟器上(iPhone 6s,iOS 9.2 - 截图上有一个小的自动布局问题 - tabbar仍然是静态320.0大小和iPhone 5s,iOS 9.2) -
但是
在设备上(iPhone 5,iOS 9.2)我在屏幕上显示了这一点(即使标签栏处于初始状态 - 每个段都被选中),屏幕上没有任何内容 -
我已经调试了每个子视图控制器框架,打印了子视图框架 - 一切都是正确的。什么可能导致这个问题?谢谢。
修改
我以下列方式管理标签栏。它属于主Tab栏视图控制器。该控制器具有以下配置方法 -
private func setUpTabBar ( forSelectedActionSignContainer imageView : UIImageView ) -> Void
{
var viewControllerIndex = 0
if ( imageView == feedSign )
{
feedSign.hidden = false
exploreSign.hidden = true
cameraSign.hidden = true
chatSign.hidden = true
profileSign.hidden = true
viewControllerIndex = 0
}
if ( imageView == exploreSign )
{
feedSign.hidden = true
exploreSign.hidden = false
cameraSign.hidden = true
chatSign.hidden = true
profileSign.hidden = true
viewControllerIndex = 1
}
if ( imageView == cameraSign )
{
feedSign.hidden = true
exploreSign.hidden = true
cameraSign.hidden = false
chatSign.hidden = true
profileSign.hidden = true
viewControllerIndex = 2
}
if ( imageView == chatSign )
{
feedSign.hidden = true
exploreSign.hidden = true
cameraSign.hidden = true
chatSign.hidden = false
profileSign.hidden = true
viewControllerIndex = 3
}
if ( imageView == profileSign )
{
feedSign.hidden = true
exploreSign.hidden = true
cameraSign.hidden = true
chatSign.hidden = true
profileSign.hidden = false
viewControllerIndex = 4
}
displayViewController(atIndex: viewControllerIndex)
}
栏中的每个标签都有自己的动作,底部的每条绿线都有它的出口:
@IBAction func feedControllerSelected()
{
setUpTabBar(forSelectedActionSignContainer: feedSign)
}
@IBAction func exploreControllerSelected()
{
setUpTabBar(forSelectedActionSignContainer: exploreSign)
}
@IBAction func cameraControllerSelected()
{
setUpTabBar(forSelectedActionSignContainer: cameraSign)
}
@IBAction func chatControllerSelected()
{
setUpTabBar(forSelectedActionSignContainer: chatSign)
}
@IBAction func profileControllerSelected()
{
setUpTabBar(forSelectedActionSignContainer: profileSign)
}
private func initialSetUp()
{
setUpTabBar(forSelectedActionSignContainer: feedSign)
}
在tabbar控制器的viewDidAppear
中,我通过调用setUpTabBar(forSelectedActionSignContainer: feedSign)
进行初始配置。因此,儿童控制员无法管理任何内容,并在原始UITabbarController
编辑2
当我向子视图控制器添加UITableView
时,所有这些都发生在设备上。没有它 - 一切正常。看起来设备上有一些例外,但它不会以某种方式通过电线传播到xcode。
答案 0 :(得分:0)
经过4个小时的调查后,我发现了以下情况:
UITabbarController
UITableViewCell
中,肯定是自定义的,我有水平滚动条 - HorizontalTableView
形成GitHub。<强>概要强>
谢谢大家!