0
votes

Hi Everyone I'm Experiencing 2 errors when I'm running my app with a slide out menu

class ViewController: UIViewController {

    @IBOutlet var open: UIBarButtonItem!
    @IBOutlet var label: UILabel!

    var varView = Int()

    override func viewDidAppear(_ animated: Bool) {

        open.target = revealViewController()
        open.action = #selector(SWRevealViewController.revealToggle(_:))
        _ = UIStoryboard(name: "Main", bundle: nil)
        let vc = (storyboard?.instantiateViewController(withIdentifier: "mainpullout"))! as UIViewController
        present(vc, animated: true, completion: nil)
    }

    @IBAction func toMain(_ sender: AnyObject?) {
        _ = UIStoryboard(name: "Main", bundle: nil)
    }
}

here is my class for my slide out controller that controls all the views in the table

class BackTableVC: UITableViewController {

    var TableArray = [String]()

    override func viewDidLoad() {
        TableArray = ["Camps","Lessons","Staff","Classes","Calendar","News","Forums","Locations","Services","Home"]
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return TableArray.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: TableArray[indexPath.row], for: indexPath) as UITableViewCell

        cell.textLabel?.text = TableArray[indexPath.row]

        return cell   
    }
}

i feel like I'm doing something wrong but when i run my app it the view where the button is to open the slide out menu just bounces up and down a million times heres one of the error messages

Presenting view controllers on detached view controllers is discouraged

1
you are populating your data wrong. read a bit about how to implement UITableView in Swift - JuicyFruit
JuicyFruit are you saying that how I'm putting my table code in to say what i need to show up is wrong if so do you have any idea on how i can fix it - westonadam54
let cell = tableView.dequeueReusableCell(withIdentifier: TableArray[indexPath.row], for: indexPath) as UITableViewCell is wrong, check UITableView tutorials about what cell id is - JuicyFruit

1 Answers

0
votes

you should do it inside viewDidLoad and reference instance, not class like

override func viewDidLoad() {
    super.viewDidLoad()
    self.open.target = self.revealViewController()
    self.open.action = #selector(revealViewController().revealToggle(_:))
}

however I had to create custom revealToggle function some time ago, if my code doesn't work - I will suggest one more solution.