skip to Main Content

When i tap this edit button then i want to open WolverineVC

    class XibFileController: UIView {

           // This Is XIB controller File
           @IBAction func editButtonTapped(_ sender: UIButton) {
               // TODO: Click here to open wolverineVC
           }
    }

here is the Xib Fileenter image description here

here is my Storyboard file

enter image description here

4

Answers


  1. let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let viewController = storyboard.instantiateViewController(identifier: "premiumPage")
    self.present(viewController, animated: true, completion: nil)
    
    • firstly, lets create a storyboard and then give a name (if your storyboard name is "Main.storyboard" the name is "Main" or Wolverine.storyboard -> name is: "Wolverine")
    • go to your storyboard click on the page you want to open and give an identifier to it. (it name is Storyboard ID. seen in picture 2)
    • now add above code to editButtonTapped function
    • that’s it
    Login or Signup to reply.
  2.   guard let viewController = UIStoryboard(name: "Wolverine", bundle: nil).instantiateViewController(withIdentifier: "WolverineVC") as? WolverineVC
            else {
                return
            }
            self.navigationController?.pushViewController(viewController, animated: true)
    

    You need to add a storyboard ID to instantiate your storyboard.

    enter image description here

    edit: according to your updated question.

    protocol XibDelegate: AnyObject {
     func openWolverineVC(value: Bool)
    }
    
    class XibFileController: UIView {
    
            weak var delegate: XibDelegate?
    
           // This Is XIB controller File
           @IBAction func editButtonTapped(_ sender: UIButton) {
               self.delegate?.openWolverineVC(value: true)
           }
    }
    

    Your main view controller should be like this:

        final class MainViewController: UIViewController, XibDelegate {
        
    
      override func viewDidLoad() {
         super.viewDidLoad() 
         xibReference.delegate = self
      }
    
      func openWolverineVC(value: Bool) {
       guard let viewController = UIStoryboard(name: "Wolverine", bundle: nil).instantiateViewController(withIdentifier: "WolverineVC") as? WolverineVC
                else {
                    return
                }
         viewController.boolValue = value
         self.present(viewController, animated: true)
      }
    
    }
    
    Login or Signup to reply.
  3. I have a view that I created with xib. Clicking on the image in the view will direct it to the view controller I created in the storyboard. However, it doesn’t happen anyway. Xib view code like this:

    import UIKit
    class BookDetailVideoViewController: UIViewController{
    
        var book : Book?
        var videoUrl = ""
        var url: URL?
        var index = 0
    
        @IBOutlet weak var bookImageView: UIImageView!
        //var book = self.book
        
        @IBOutlet weak var bookImageViewWidthConstraint: NSLayoutConstraint!
        
        override func viewDidLoad() {
            super.viewDidLoad()
    
            if #available(iOS 11.0, *) {
                self.extendedLayoutIncludesOpaqueBars = true
            } else {
                self.edgesForExtendedLayout = []
            }
            self.navigationController?.navigationBar.isTranslucent = false
            //self.bookImageViewWidthConstraint.constant = UIScreen.main.bounds.width * 0.35
            self.view.layoutIfNeeded()
    
            if let url = self.url {
                self.bookImageView.kf.setImage(with: url)
            }
            
            self.bookImageView.layer.cornerRadius = 10
            bookImageView.isUserInteractionEnabled = true
            let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageClicked))
            bookImageView.addGestureRecognizer(gestureRecognizer)
        }
        
        override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
        }
        
        deinit {
            self.url = nil
        }
        
        @objc func imageClicked(){
       
            let backItem = UIBarButtonItem()
            backItem.title = ""
            self.navigationItem.backBarButtonItem = backItem
            if let vc = Bundle.main.loadNibNamed("YoutubeVideoViewController", owner: nil, options: nil)?.first as? YoutubeVideoViewController {
                vc.book = book
                vc.present(vc, animated: true, completion: nil)
            }
        }
    
        func initializeView(url: URL, index: Int , book: Book) {
            self.index = index
            self.url = url
            self.book = book
        }
    
        override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
    
        }
    }
    

    BokkdeatilVideoViewController

    Login or Signup to reply.
  4. YoutubeViewController is the viewController I created in the storyboard. I could not switch from xib to this view.

    import UIKit
    import YoutubePlayer_in_WKWebView
    
    class YoutubeVideoViewController: UIViewController {
        var photoTapped: (() -> Void)?
        var book : Book?
        @IBOutlet weak var playerView: WKYTPlayerView!
        override func viewDidLoad() {
            super.viewDidLoad()
            let mediakey = book!.mediaKey as String?
            playerView.load(withVideoId: mediakey!)
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search