0

I would like to know if it is possible to add an item into a TabBarController without any ViewController associate. In this way if you press this item the screen don't go to any ViewController and you can create an action to this item.

I think that it is impossible if you try to add an item without any ViewController in through StoryBoard. So, I thought in added it manually but it doesn't let me modify the TabBar programmatically:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'

UPDATE:

This is an example of how I tried to add items programatically:

class TabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let item1 = UITabBarItem(title: "item1", image: nil, selectedImage: nil)
        let item2 = UITabBarItem(title: "item2", image: nil, selectedImage: nil)
        let items = [item1, item2]

        self.tabBar.setItems(items, animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

}
angeldev
  • 1,983
  • 3
  • 18
  • 29
  • 1
    TabBAr is contained in tab bar controller.If you want to modify it, it has to be done through tab bar controlller. If you want to customise it, create your own tab bar from uiview. – Teja Nandamuri Feb 11 '16 at 16:18
  • @Mr.T I had a TabBarController and I can't modify its items programatically. So, do I have to create a custom TabBar? – angeldev Feb 11 '16 at 16:20
  • How you are modifying it ? Could you please show some code related to it. Tab bar doesnt allor you to do much stuff about customising. It is always better to create custom tab bar if you need more customisation. – Teja Nandamuri Feb 11 '16 at 16:21
  • @Mr.T I added some code of one way I tried to modify it programmatically. This is the ideal solution because I don't have to set any ViewController but it launch the exception. – angeldev Feb 11 '16 at 16:30
  • http://stackoverflow.com/questions/26850411/how-add-tabs-programmatically-in-uitabbarcontroller-with-swift – Teja Nandamuri Feb 11 '16 at 16:32
  • @Mr.T It is work, so the problem was that I was trying to modify `tabBar` instead of the TabBarController directly. But if this is the case the main issue (create an TabBarItem without any ViewController associate) is impossible. – angeldev Feb 12 '16 at 11:42

0 Answers0