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?
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
If isMemberOfClass_(rootWiewControllerPtr,NSClassFromString("UITabBarController")) Then
Declare Sub setSelectedIndex Lib "UIKIT" selector "setSelectedIndex:"(tbPtr As Ptr,page As UInteger)
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)
Actually I just re-read your question and I don’t think this is the solution you need.
Something like this seems to work, but I wasn’t able to set any iOSToolbutton on the new views to close the second tabbar
[code]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
Dim v4 As new View4
presentViewController(self.Handle, navController, True, Nil)
Hi Jrmie, 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.