iOSView.pushto a different tab bar

  1. last week

    Gavin S

    Dec 6 Pre-Release Testers, Xojo Pro UK

    I have an iPhoneScreen with a tab bar and the main iOSView has an iOSTable. When a row is tapped, I'd like to pushto another iOSView which would have a second, different tab bar.

    I could simply swap out the iOSApplication.currentscreen but I want to retain the view hierarchy so I need to .pushto the second view. I could do this in Swift but I can't think how to do it in Xojo. Any thoughts?

  2. 7 days ago

    Jason T

    Dec 6 Pre-Release Testers, Xojo Pro Sydney, Australia

    Antonio Rinaldi posted this method in the forum and I believe it is now incorporated into iOSDesignExtensions (at least it's in my copy):

    Public Sub SetTabPageXC(idx as integer, doReset as Boolean = False)
      'This method has been posted in the forum by Antonio Rinaldi.
      'It allows setting the active tab like if the user had tapped himself on the tab icon, without need for PushTo.
      'Index is zero based, left to right
      
      
      
      If idx<0 Then Return
      Declare Function NSClassFromString Lib "Foundation"(cls As CFStringRef) As Ptr
      Declare Function sharedApplication_ Lib "UIKit" selector "sharedApplication"(cls_ptr As Ptr) As Ptr
      Dim shAppPtr As Ptr=sharedApplication_(NSClassFromString("UIApplication"))
      
      Declare Function keyWindow_ Lib "UIkit" selector "keyWindow"(app_ptr As Ptr) As Ptr
      Dim keyWinPtr As Ptr=keyWindow_(shAppPtr)
      
      Declare Function rootWiewController_ Lib "UIKit" selector "rootViewController"(winPtr As Ptr) As Ptr
      Dim rootWiewControllerPtr As Ptr=rootWiewController_(keyWinPtr)
      
      Declare Function isMemberOfClass_ Lib "foundation" selector "isMemberOfClass:"(oPtr As Ptr,cPtr As Ptr) As Boolean
      Dim a As ptr
      a=NSClassFromString("UITabBarController")
      If isMemberOfClass_(rootWiewControllerPtr,NSClassFromString("UITabBarController")) Then
        Declare Sub setSelectedIndex Lib "UIKIT" selector "setSelectedIndex:"(tbPtr As Ptr,page As UInteger)
        setSelectedIndex(rootWiewControllerPtr,idx)
        
        If doReset Then
          Declare Function selectedViewController_ Lib "UIKIT" selector "selectedViewController"(oPtr As ptr) As Ptr
          Dim navPtr As Ptr=selectedViewController_(rootWiewControllerPtr)
          Declare Sub popToRoot Lib "UIKIT" selector "popToRootViewControllerAnimated:"(oPtr As Ptr,animated As Boolean)
          popToRoot(navPtr,True)
        End If
      End If
      
    End Sub
  3. Jason T

    Dec 6 Pre-Release Testers, Xojo Pro Sydney, Australia

    Actually I just re-read your question and I don't think this is the solution you need.

  4. Jeremie L

    Dec 6 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io
    Edited 7 days ago

    Something like this seems to work, but I wasn't able to set any iOSToolbutton on the new views to close the second tabbar

    Dim tView As new iOSTabBar
    
    
    
    Declare Function NSClassFromString Lib "Foundation" (className As CFStringRef) As Ptr
    Declare Function alloc Lib "Foundation.framework" selector "alloc" (clsRef As ptr) As ptr
    Declare Function initWithRootViewController_ Lib "Foundation" selector "initWithRootViewController:" (obj_id As ptr, rootViewController As ptr) As ptr
    Declare Sub presentViewController Lib "UIKit.framework" _
    Selector "presentViewController:animated:completion:" _
    (parentView As Ptr, viewControllerToPresent As Ptr, animated As Boolean, completion As Ptr)
    Declare Sub modalPresentationStyle_ Lib "UIKit.framework" selector "setModalPresentationStyle:" (obj_id As ptr, modalPresentationStyle As UIModalPresentationStyle)
    
    
    
    'Dim navController As ptr = tView.ViewControllerHandle
    Dim navController As ptr = initWithRootViewController_( alloc(NSClassFromString("UINavigationController")), tview.ViewControllerHandle ) 
    
    
    
    //Setting up the tabs
    Dim v3 As new View3
    tView.AddTab(v3)
    
    
    Dim v4 As new View4
    
    tView.AddTab(v4)
    
    
    presentViewController(self.Handle, navController, True, Nil)
  5. 5 days ago

    Gavin S

    Dec 8 Pre-Release Testers, Xojo Pro UK

    Hi Jérémie, thanks for that, and for the email, much appreciated. Yes, apart from the navigation bar not working on the second view, that's a good solution. In the end, I redesigned the app a little and didn't require the change of tabs but I'll keep your solution for future use. Thanks again.

or Sign Up to reply!