Ola
Ola

Reputation: 431

Swift-UICollectionView in UIView Container

I have three sections, the header and a container where a tab bar can facilitate transition of pages all within that container. I want to build a UI like the figure below.Objective

My approach is to create two container views one for the header and the other for tabbar and selected pages. The tabbar and selected pages are UICollectionViewCell. So I will be putting UICollectionViewCell in a UIView container.

in my BusinessHomeViewController.swift file

class BusinessHomeViewController: UIViewController {
 let businessPagesContainer: BusinessPages = {
   let bp = BusinessPages()
    return bp
}()
  func setupbusinessPagesContainerView(){
    businessPagesContainer.heightAnchor.constraint(equalToConstant: 80).isActive = true
    businessPagesContainer.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true

    businessPagesContainer.topAnchor.constraint(equalTo: businessDescriptionView.bottomAnchor, constant: 90).isActive = true

    view.addSubview(menuBar)
    menuBar.topAnchor.constraint(equalTo: pageToggleContainer.topAnchor, constant: 2).isActive = true
    menuBar.centerXAnchor.constraint(equalTo: pageToggleContainer.centerXAnchor).isActive = true

}

 override func viewDidLoad() {
    super.viewDidLoad()

            view.addSubview(businessPagesContainer)
              setupbusinessPagesContainerView()
    }
    }

In my BusinessPages.swift file

import UIKit

class BusinessPages: UICollectionViewCell {

override init(frame: CGRect) {
    super.init(frame: frame)

}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
}

When I run the app, it crashes and gave this error "terminating with uncaught exception of type NSException". Is my approach wrong and how can I fix this?

Upvotes: 0

Views: 275

Answers (1)

ViralRathod
ViralRathod

Reputation: 324

If you're running into this problem make sure that you go to Main.storyboard, RIGHT click on the yellow box icon (view controller) at the top of the phone outline and DELETE the outlet(s) with yellow flags.

enter image description here

Upvotes: 1

Related Questions