Try to search your question here, if you can't find : Ask Any Question Now ?

Unable to access UIView subclass IBOutlets From TabBarController

HomeCategory: stackoverflowUnable to access UIView subclass IBOutlets From TabBarController
Avatarbhawya asked 5 months ago

I have a UIView Class with xib. I try to add it in another ViewControllers as a popover view. I have outlet connections. But when I run the application it crashed and stated

This class is not key value coding-compliant for the key btnAbtUs

I think the problem is should select delegate. I may using wrong way to add this xib. Any one please help me to correct. Here is my code.

//UIView Class

class MoreView: UIView {

    @IBOutlet var containerView: UIView!

    @IBOutlet weak var btnAboutUs: UIButton!

    override public func awakeFromNib() {

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

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

    func loadViewFromNib() {
        let bundle = Bundle(for: type(of: self))

        let nib = UINib(nibName: "MoreView", bundle: bundle)
        let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView

        view.frame = bounds
        view.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        self.insertSubview(view, at: 0)


    private func commitInit(){

        containerView.translatesAutoresizingMaskIntoConstraints = true

        self.btnAboutUs.addTarget(self, action: #selector(self.clickAboutUs(_:)), for: .touchUpInside)

    class func instanceFromNib() -> UIView {

        return UINib(nibName: "MoreView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! UIView

    @objc func clickAboutUs(_ sender: Any) {


func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {

    let moreView = MoreView.instanceFromNib

    if let navigationController = viewController as? UINavigationController,
        navigationController.viewControllers.contains(where: { $0 is MoreViewController }) {
        moreView().frame.origin.y = 100

        return false
    } else  {
        return true
1 Answers
Best Answer
Avatarnaveen answered 5 months ago
Your Answer

15 + 16 =

Popular Tags

WP Facebook Auto Publish Powered By :