Disable one of the Tabs

  1. 4 years ago

    Jaap C

    27 Jan 2016 Pre-Release Testers, Xojo Pro Europe, Holland

    I have a screenlayout which is set to content Tabs.
    It has 3 tabs, but sometimes one of these tabs hase no function.

    Is it possible to disable or remove and add it again during runtime?

    Use this method (put in a module since is an extension)
    Then call it as:
    self.tabItemEnable(1)=false

    Sub tabItemEnable(extends view as iOSView, index as integer, assigns value as Boolean)
      dim tb as iOSTabBar=view.ParentTabBar
      if tb is nil then Return
      dim h as ptr=tb.ViewControllerHandle
      
      Declare Function tabbar_ lib "UIKit" selector "tabBar"(o as Ptr) as Ptr
      dim tabbar as Ptr=tabbar_(h)
      
      declare Function items_ lib "UIKit" selector "items"(o as Ptr) as Ptr
      dim items as Ptr=items_(tabbar)
      
      Declare Function count_ lib "foundation" selector "count"(o as Ptr) as Integer
      dim count as integer=count_(items)
      if index<count then
        Declare Function objAtIndex lib "foundation" selector "objectAtIndex:"(o as Ptr, idx as Integer) as Ptr
        dim item as Ptr=objAtIndex(items,index)
        
        Declare sub setEnabled lib "UIKit" selector "setEnabled:"(o as Ptr, v as Boolean)
        setEnabled(item, value)
      end if
     End Sub
  2. Derek D

    27 Jan 2016 Pre-Release Testers Newnan, GA. USA

    Maybe this will help? https://forum.xojo.com/4716-disable-a-tab/0

  3. Antonio R

    28 Jan 2016 Pre-Release Testers, Xojo Pro, Third Party Store Answer Europe (Italy)

    Use this method (put in a module since is an extension)
    Then call it as:
    self.tabItemEnable(1)=false

    Sub tabItemEnable(extends view as iOSView, index as integer, assigns value as Boolean)
      dim tb as iOSTabBar=view.ParentTabBar
      if tb is nil then Return
      dim h as ptr=tb.ViewControllerHandle
      
      Declare Function tabbar_ lib "UIKit" selector "tabBar"(o as Ptr) as Ptr
      dim tabbar as Ptr=tabbar_(h)
      
      declare Function items_ lib "UIKit" selector "items"(o as Ptr) as Ptr
      dim items as Ptr=items_(tabbar)
      
      Declare Function count_ lib "foundation" selector "count"(o as Ptr) as Integer
      dim count as integer=count_(items)
      if index<count then
        Declare Function objAtIndex lib "foundation" selector "objectAtIndex:"(o as Ptr, idx as Integer) as Ptr
        dim item as Ptr=objAtIndex(items,index)
        
        Declare sub setEnabled lib "UIKit" selector "setEnabled:"(o as Ptr, v as Boolean)
        setEnabled(item, value)
      end if
     End Sub
  4. Jason T

    28 Jan 2016 Pre-Release Testers, Xojo Pro Sydney, Australia
    Edited 4 years ago

    Hey Antonio...while you've got tabs on your mind...I don't suppose you have a declare to add a banner to a tab? You know, one of those red dots with a number in it for notifications? I'd like to notify my users when they have new data in one of my tabs. :)

  5. Jason T

    28 Jan 2016 Pre-Release Testers, Xojo Pro Sydney, Australia

    Actually I think I've answered my own question. Changing value to a text parameter and replacing the last call to setEnabled with this code seems to work for setting the tab banner:

          declare sub setBadgeValue lib "UIKit" selector "setBadgeValue:" (o as ptr, value as cfstringref)
          setBadgeValue item, value
  6. Antonio R

    28 Jan 2016 Pre-Release Testers, Xojo Pro, Third Party Store Europe (Italy)

    Yes, now the module can be named tabBarExtension ;)

or Sign Up to reply!