ENSwiftSideMenu icon indicating copy to clipboard operation
ENSwiftSideMenu copied to clipboard

in case of two type of user login how to update menu table and functionality

Open atestcode opened this issue 10 years ago • 13 comments

in case of two type of user login how to update menu table and its functionality.

there are one situation where app have two type of user login and according to that user menu and its functionality but in this menu table created before the user selection.

atestcode avatar Oct 29 '15 10:10 atestcode

how do i update menu items based on user.

I want to change the content of menu based login user.

manishpurplefront avatar Nov 04 '15 11:11 manishpurplefront

I have the same question, i need to call func to logout from the side menu table, then update the side menu table to no longer show the LOGOUT cell ;) ..

hopye avatar Nov 07 '15 03:11 hopye

i have tried using a protocol and delegate.. the func is never called.. don't know why..

hopye avatar Nov 07 '15 03:11 hopye

Can you tell me which protocol and delegate I can write to change contents on side menu.

manishpurplefront avatar Nov 07 '15 11:11 manishpurplefront

Hi, the lib doesn't handle side menu content state. you need to implement your own logic to do this. for example you can use nsnotifications.

evnaz avatar Nov 07 '15 11:11 evnaz

@evnaz im kind of newbi to iOS and swift. can you pin point me on how to to this ? . i have the ensidemenu getting the content from the uitableviewviewcontroller like in the example * MyMenuTableViewcontroller , there i have an array of menuitems = ["home","contact"] . what i do is i check first in the viewWillappear via nsuserdefaults wether the user is logged via a bool , if( logged == true ) { .. it adds self.menuitems.append("logout") .. , it works if already logged in, start app .. it checks for the state of logged and adds the array, but then .. if i log out , sync nsuderdefaults and open the menu again, LOGOUT remains there.. i will like to update the array and reload the tableview before it opens.. and or // why even the viewWillAppear or viewdidload, only checks the first time for logged.. is like the view loads one time.. and stays there in memory... so.. no even viewwillappear in the uitableviewcontroller does the trick for me ..

hopye avatar Nov 07 '15 19:11 hopye

Just to test , the first view controller inside the sidemenuwillopen() .. func sideMenuWillOpen() { print("sideMenuWillOpen") //sideMenuController()?.sideMenu?. let a = MyMenuTableViewController() a.foo() }

--- on my mymenutablecontroller --

func foo() { self.menuitems.append("Logout YES") tableView.reloadData() print("foooooooooo") print(" Count in menuitems is (self.menuitems.count) "); for a in self.menuitems { print(a) }
}


in the console output i see the array adds the item, but the table doesn't reload.. :/

hopye avatar Nov 07 '15 23:11 hopye

This is killing me, cant still figure out. Cant update the tableviewcontroller...

hopye avatar Nov 08 '15 14:11 hopye

in the last version of the lib you can get side menu view controller instance by self.sideMenuController()?.sideMenu?.menuViewController just call reloadData() on it whenever you need

evnaz avatar Nov 08 '15 15:11 evnaz

@evnaz can u add my to Skype : LGONGALEZ
i need to show you..please 2 min. promised.

hopye avatar Nov 08 '15 18:11 hopye

@evnaz please check https://youtu.be/nfhShPTivZ0 , after the first 20 secs.. and finish the video.. lol

hopye avatar Nov 08 '15 23:11 hopye

i did it thnx to you @evnaz! , im calling the foo() of MyMenuTableViewController, that will first if the user is logged or not and update the table accordly

func sideMenuWillOpen() {
    print("sideMenuWillOpen")
  //  let a = MyMenuTableViewController()
   // a.foo()
let menu = self.sideMenuController()?.sideMenu?.menuViewController as! MyMenuTableViewController
    menu.foo()   
}

hopye avatar Nov 09 '15 02:11 hopye

Thanks this solution also worked for me. For those who are facing same problem here is description that you have to do

Add this function to class MyMenuTableViewController and customise it according to your need and call tableView.reloadData()

func foo() { //self.menuitems.append("Logout YES") tableView.reloadData() print("foooooooooo") print(" Count in menuitems is (self.menuitems.count) "); //for a in self.menuitems { //print(a) //} }

Add this code from where you want to update menu

let menu = self.sideMenuController()?.sideMenu?.menuViewController as! MyMenuTableViewController menu.foo()

and don't forget to add ENSideMenuDelegate to class above code is being called.

manishpurplefront avatar Dec 01 '15 11:12 manishpurplefront