Quantcast
Viewing all articles
Browse latest Browse all 1318

Swift Push ViewController from FlexLayout View

I basically followed the tutorial from FlexLayout on making a series of remote Views.

That part went extremely well... But I'd like to make the clicking on each of the individual views push a different ViewController. I'm using tap gestures to make each of the views clickable... but neither love nor money will get them to actually take me to a ViewController.

If I try to present them I get:

Warning: Attempt to present on whose view is not in the window hierarchy

And if I try to push them I get some sort of nil error:

A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs.

Here's the code:

SocialView

import FlexLayoutprotocol SocialViewDelegate {    func didTapButton()}class SocialView: UIView {    var delegate: SocialViewDelegate?    @IBOutlet weak var view1: UIView!    @IBOutlet weak var view2: UIView!    fileprivate let rootFlexContainer = UIView()    init() {        super.init(frame: .zero)        backgroundColor = .white        let view1 = UIView()        let view2 = UIView()        let text1 = UILabel()        text1.text = "Photos"        view1.backgroundColor = .white        view1.addSubview(text1)        let tap = UITapGestureRecognizer(target: self, action: #selector(goEvt))                //tap.delegate = self                view1.addGestureRecognizer(tap)    @objc func goEvt() {        //let vc2 = UsersViewController()        //vc2.modalPresentationStyle = .fullScreen        //let vc93 = SocialViewController(coder: aDecoder)        let vip = SocialViewController()        let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)        let vc = storyBoard.instantiateViewController(withIdentifier: "evview") as! EventsViewController       // vip.present(vc, animated: true)        vip.didTapButton()}     //   self.collectionView.addSubview(vc)    }    @objc func buttonTapAction() {            delegate?.didTapButton()        }

SocialViewController

class SocialViewController: UIViewController, SocialViewDelegate {    func didTapButton() {        let topdawg = EventsViewController()        let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)        let vc = storyBoard.instantiateViewController(withIdentifier: "evview") as! EventsViewController        self.present(topdawg, animated: true)       // navigationController?.pushViewController(topdawg, animated: true)    }    fileprivate var mainView: SocialView {        return self.view as! SocialView    }

For this part:

let tap = UITapGestureRecognizer(target: self, action: #selector(goEvt))

You could put "goEvt" or "didTapButton"... One would keep you on SocialView, the other would take you to SocialViewController. Doesn't matter. You can also see that I've commented out a few things I've tried... It all leads to either the first or second error I posted above.

I can't make it to "EventsViewController" (or any other) no matter what I do.

So any help would be appreciated.


Viewing all articles
Browse latest Browse all 1318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>