Home Protocol and delegate not working
Reply: 0

Protocol and delegate not working

user2746 Published in March 23, 2018, 10:33 pm
import UIKit

class TabBarViewController: UITabBarController, selectedTopic {

    func selectedTopic(topicIndex: Int) {
        self.selectedIndex = topicIndex

    override func viewDidLoad() {

        let menuViewController = MenuViewController()
        menuViewController.delegate = self

        tabBar.isHidden = true



import UIKit

protocol selectedTopic {
    func selectedTopic(topicIndex : Int)

class MenuViewController: UIViewController {

    @IBOutlet weak var TapViewButton: UIView!
    @IBOutlet weak var UpgradeViewButton: UIView!
    @IBOutlet weak var TopicTitle: UILabel!
    @IBOutlet weak var LeaderboardViewButton: UIView!
    @IBOutlet weak var ShopViewButton: UIView!
    @IBOutlet weak var StatisticsViewButton: UIView!

    var delegate : selectedTopic?

    override func viewDidLoad() {

        delegate?.selectedTopic(topicIndex: 0)

        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(changeToTapSegue))

        let upgradeGesture = UITapGestureRecognizer(target: self, action: #selector(changeToUpgradeSegue))

        let leaderboardGesture = UITapGestureRecognizer(target: self, action: #selector(leaderboardViewTouched))
        let shopGesture = UITapGestureRecognizer(target: self, action: #selector(shopViewTouched))
        let statisticsGesture = UITapGestureRecognizer(target: self, action: #selector(statisticsViewTouched))


    @objc func changeToTapSegue() {

        self.performSegue(withIdentifier: "TapSegue", sender: self)

    @objc func changeToUpgradeSegue() {

        self.performSegue(withIdentifier: "UpgradeSegue", sender: self)

    @objc func leaderboardViewTouched() {

        TopicTitle.text = "Leaderboard"


    @objc func shopViewTouched() {

        TopicTitle.text = "Shop"

    @objc func statisticsViewTouched() {
        TopicTitle.text = "Statistics"


When the code is ran the view controller doesn't receive the data. It doesn't even run. I check this by placing print(self.selectedIndex) in the the function that receives the data. Nothing was printed in the console. Can you please help me solve this problem. I feel like it has something do to with setting the delegate. Can you please help me find the problem so I can fix it.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.298606 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO