iOS Question Mutliple Pages with Side Menu

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I think I am doing something wrong but can't work it out.

I have been using the Multiple Page example tutorial - https://www.b4x.com/android/forum/threads/multiple-pages-example.48170/#content

I am trying to add a side menu to one page only.

For example, PagePage1Module to show the side menu but the rest not to show the side menu.

I have used the following code, and everything works and shows the side menu, but if I try and show another page after viewing the page which contains the side menu then it doesn't show the new page.

Main Page shows and loads the LoginModule.
LoginModule asks for the name, and I press Enter.
This then shows the page with a button that says 'Select color'

When I press that button, it seems to run that sub, but it fails to load the ColorsModule screen.

I am guessing I am doing this wrong.

Any ideas on what I have done wrong ?

I have followed the tutorial above for the multiple pages, and then checked out the side menu tutorials but can't work out how to merge the two together.

I only want to display the side menu on one screen only and not all screens.

PageModule Code:
(All other pages/modules from the Multiple pages tutorial is the same code)
B4X:
'Code module

Sub Process_Globals
    Private btnSelectColor As Button
    Private Label1 As Label
    Private SMC As SideMenuController
    Public NavControl1 As NavigationController
    Dim myapp As Application
    Dim MainPage As Page
End Sub

Public Sub Show

    'create a new navigation controller
    Dim nc As NavigationController
    nc.Initialize("nc")
    NavControl1 = nc
    
    ' Main Page
    
    MainPage.Initialize("MainPage")
    MainPage.Title = "Page 1"
    MainPage.RootPanel.Color = Colors.White
    MainPage.RootPanel.LoadLayout("Page1Layout")
    
    ' Left Menu
    Dim lp As Page
    lp.Initialize("lp")
    lp.RootPanel.Color = Colors.Red
    lp.RootPanel.LoadLayout("leftmenu")
    
    SMC.Initialize(lp, nc, Null)
    
    myapp.KeyController = SMC
    nc.ShowPage(MainPage)
    
End Sub

Private Sub btnSelectColor_Click
    Log("btnSelectColor_Click")
    ColorsModule.ShowModule   
End Sub

Public Sub ReturnFromColors(SelectedColor As Int)
    Main.NavControl.ShowPage(MainPage)
    MainPage.RootPanel.Color = SelectedColor
End Sub
 

aaronk

Well-Known Member
Licensed User
Longtime User
Please upload the project.
See attached.

I think I might of got it working, but want to double check I have done it correct.

The non-working example attached is based on Post 1 above.
The working example attached is some changes I have made and it seems to be working. Is this code correct?

I recommend you to use B4XDrawer for new projects
I already have my B4A working and don't plan to change it at this stage. The B4i project is still new but I have done a lot of work already and plan to follow with the iSideMenu for now. Maybe I will look at this B4XDrawer at a later time.
 

Attachments

  • working.zip
    9.8 KB · Views: 190
  • not_working.zip
    8.2 KB · Views: 179
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm getting the following error when I press on the enter button:

Copying updated assets files (4)
Application_Start
Application_Active
Error occurred on line: 35 (Page1Module)
Expected: UINavigationController, object type: MMDrawerController
Stack Trace: (
CoreFoundation <redacted> + 252
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation <redacted> + 0
B4i Example -[B4IObjectWrapper setObject:] + 280
B4i Example -[b4i_page1module _show] + 2372
B4i Example -[b4i_loginmodule _btnenter_click] + 436
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
B4i Example -[B4IShell runMethod:] + 448
B4i Example -[B4IShell raiseEventImpl:method:args::] + 2164
B4i Example -[B4IShellBI raiseEvent:event:params:] + 1372
B4i Example __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
libdispatch.dylib <redacted> + 24
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 1012
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 1964
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 100
UIKitCore UIApplicationMain + 212
B4i Example main + 124
libdyld.dylib <redacted> + 4
)
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I'm getting the following error when I press on the enter button:
Whops.. uploaded the wrong working sample.

See the attached working sample.
All pages/screen should not allow the side menu to show, and only the Page1Module (when it shows the name you entered in) should show the side menu. (which is what I want).

Is this example project the correct way in doing this ?
 

Attachments

  • WorkingSample.zip
    9.6 KB · Views: 194
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is this example project the correct way in doing this ?
No. Never initialize the same controller multiple times.

You should do something like:
Page1Module:
B4X:
Public Sub MainPage_Appear
   Main.smc.OpenGesturesEnabled = True
End Sub

Public Sub MainPage_Disappear
   Main.smc.OpenGesturesEnabled = False
End Sub

Private Sub btnSelectColor_Click
   ColorsModule.ShowModule   (nc)
End Sub

Colors module:
B4X:
Public Sub ShowModule (Parent As NavigationController)
   
   ' Main Page
   
   MainPage.Initialize("MainPage")
   MainPage.Title = "Page 1"
   MainPage.RootPanel.Color = Colors.White
   MainPage.RootPanel.LoadLayout("ColorsLayout")
   
   
   ' Left Menu
   Dim lp As Page
   lp.Initialize("lp")
   lp.RootPanel.Color = Colors.Red
   lp.RootPanel.LoadLayout("LeftSide")
   Parent.ShowPage(MainPage)
End Sub

Go over the example again and see how it avoids creating a new page each time. The above code will create a new page every call.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I think I am still doing this wrong.

I have looked over the tutorial multiple times but still stuck.

See attached project.

Looks like the pages are displaying but can't get the side menu to work.

Are you able to look over it and see what I might of done wrong, and update and re-upload the project so I can learn on what I have done wrong ?
 

Attachments

  • UpdatedExample.zip
    9.5 KB · Views: 208
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Updated example is attached.
That helps a lot. It makes sense now.

use iSideMenu instead of B4XDrawer
I did look at the B4XDrawer, but couldn't work out how to use it with multiple pages.

If I was to use that, how would you do it with multiple pages ?

I thought it might be done the same way as the iSideMenu but SideMenuController is used with the iSideMenu and didn't think it would be used with the B4XDrawer. (or is it used with the B4XDrawer as well?)

Are you able to upload an example on how it's done so I can compare the two projects ?
 
Upvote 0
Top