How to create a Hierarchical menu in iOS? - ios

In my application, I have a menu that is defined as follows. Each item on the menu is a node that has the following data attributes:
MenuText : (the text that would appear for that item)
isView : Whether this item is a leaf level item or not
subMenus : if isView is false, then there are multiple menu items under this attribute.
Thus, it is a tree structure that can go till any depth. The items in the menu can change periodically and hence the implementation has to be kept flexible. This data is stored in a plist file and read into an NSArray in the code (already implemented).
I now need to create a slide out menu on the left that will be populated by this data hierarchy. I have created the menu pane and added swipe gestures to it, all of which work fine. The menu has to be a collapsible one where clicking on one menu item expands the subViews below it. If the item clicked on is a view, then a new view is loaded on the rest of the screen with appropriate data.
The problem I am facing is the logic to populate the menu (which is a UITableView) from the NSArray data. The following are the two approaches I came up with.
Create a UITableView with as many sections as there are items at the top level of the menu. Then iterate through the menu items recursively. For each menu item that is not a view (i.e. it has subMenus), create a new section with number of rows equal to the number of subMenus under it. When I come across a menu item that is a view and has no further subMenus, add it as a row to the subsection created for the menu one level above it.
Create a menu with one section and as many rows as the number of menu items at the top level. When a menu item is clicked, insert rows under it to represent its sub-menus. When another menu item on the same level is clicked, collapse the previously expanded menu by deleting the inserted rows. When a menu item with no sub menus is clicked, the rest of the screen is populated with data.
I have tried both the approaches and not been able to go beyond the initial steps. For the first method, I understand that I need to add a UITableView as a part of UITableViewCells, which is good, but I need to do that recursively. For the second approach, I need to know the indexPath of each item clicked which can go to many levels.
I would like some suggestions here about which approach I should take and some guidance over how to go about it. Also, if there is any better way to do this, kindly advice. Thanks.

In my opinion, using UINavigationController is the easiest way. You can push as many UITableViews as you want.
If it doesn't fit your design requirement, you can try expandable UITableViews. There are few open sources:
JKExpandTableView
SDNestedTable
iOS-Tree-Component

Thanks for the responses. I ended up doing this using the following control:
Accordion for iOS
It has served my purpose beautifully and I posted it here so that someone with the same requirement may find it.

Take a look at TLIndexPathTools. It has a "Tree" extension that can do this. Try running the Outline sample project. The main task in adapting the sample project would be to write a recursive function to convert your array of nodes into an array of TLIndexPathTreeItem objects. All of the code in the controller:willChangeNode: method is examples of lazy loading and it doesn't sound like you'd need any of that.

Related

How to navigate from one dropdown menu to next dropdown menu in iOS?

In whatsapp, when we go to any particular user then at right corner there is more option (three dots menu). Then after clicking that menu, one list will come and again at last row there is navigate arrow, then after clicking on that row again new menu will come.
here is the images,
after clicking on more option, following view will appear
I want to implement this feature in my iOS Project. Anyone have any idea how to implement it ?
You can manage it with multiple ways!
First Way : Take two table view for the menu. Initially keep one tableview hidden. Then on more's click of first tableview, show second tableview and hide firt one.
Second Way : Take only one tableview and reload different data. I mean on click of main change your datasource for tableview and reload it.
DropDown menu's are considered bad practice in iOS. Use one UIAlertController to show first options, than on selecting the More show another UIAlertController.

How to destroy the side menu before move?

I use the side menu (jonkykong / SideMenu) when developing an application for iOS and ran into a problem. I need a menu that will be displayed on all ViewController, everything seems to work, but when you switch to the second controller, a new menu opens with the second controller, but the old menu. The only thing I found in the developer's questions is that it's necessary to destroy the old menu before switching to the second controller, but I have not found it anywhere. The code for my menu is exactly the same as in the example, except for the TableView in the menu itself (the list of menu items is implemented by tables) and the implementation of the standard functions of selecting on the table cell. I am hope for your help. Thank you very much.
Link to the side menu itself:
github.com/jonkykong/SideMenu
Photo1
Photo2

How to show multiple actions on a list item in iOS

I am coming from android and trying to replicate my small app to iOS. I basically have a list of things and certain actions can be taken on each thing. For example:
Colors
---------
Red <fav> <delete> <edit>
Green <fav> <delete> <edit>
...
Black <fav> <delete> <edit>
Though I have not seen many apps on iOS do this. Is this doable? Or should I have an "Edit" button on top right hand which then shows these actions?
For what you describe, namely a list of editable items, the Master-Detail-Application template seems to be a good fit. Editing these items is usually done by tapping the respective item, which then brings up the detail view. A swipe gesture usually allows to delete items from a list.
Also you can have a look at the Mail app and see how it handles the e-mail list (aka items) and one email with its text, etc (aka detail view). I would suggest a similar behavior for your app.
Use UITableView to show the list of items.
Refer this link to know about UITableView : https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html
In UITableView, You can create the custom cell and add your buttons (fav,delete,edit) on it.
Please refer this link as well : http://www.appcoda.com/customize-table-view-cells-for-uitableview/
Thanks!

How to Make UITableViewSections respond to a click to bring up another view controller, using NSFetchedResultsController and Core Data

I have a fairly simple but working app right now; it's my first app and I'm working through the processes.
There are 4 Tab Bars with Table View controllers with a plus button on the top right. The user clicks that button and is presented modally with a Modal View Controller. They are asked to fill in 4 sets of information in text fields and when they click save, it saves it to the Core Data database, dismisses the View and adds that information to the Table Views. Let's call the items that the user fills in:
Name
Title
Date
Amount
The 4 tab bars are just different views of the same information. For example, Tab Bar 1 has Date as the section header and name, Amount and Title in each row. Nice and easy.
Tab Bar 2 has Name in the section title with Date, Amount and Title in the row. Tab Bar 3 has Title in the section title, etc. You get the idea.
Rather than just doing this though, in Tab 2, 3 and 4, I want to actually JUST have the section headers as buttons of some form that when clicked, takes a user to that particular entry. For example, in Tab Bar 2, I have the name as the section - I want to remove the rows associated with that entry and have just sections (or buttons) with the Names; I click on a name and it takes me to another view controller which will contain all of the Title, Amount, Dates, information, etc.
My question is, what's the best way to go about this approach of removing the rows in the sections and somehow making the sections clickable buttons?
My thinking is rather than use tableViews, use buttons, etc, but is there an elegant way to do this with having already implemented NSFetchedResultsController for each of the table views in each of the Tab Bars.
Any assistance would be massively appreciated.
Thanks,
EDIT:
I have just thought of a possible way to achieve this and it would be great if anyone could validate my thoughts. Rather than create a button, have a UICollectionView in the Tab 2, 3 and 4 providing the attributes from Core Data. So the UICollectionView for tab 2 can assign the NAME attribute to the label inside the Cell and then it can act like a cell and be clicked on. This sounds like the most feasible way to achieve this.

how to do drag and drop of record from one list view to another kendoUI

I have different list views,
I want to drag and drop of record from one list view to another.
I have seen a link in regarding this,
"http://jsfiddle.net/MZxQu/36/"
I have implemented this in list view,with this I am able to drag the list view content,but I am not able to drop it on another list view.
can u help me
Thanks..
Use this instead of grid it will be better i guess:
http://demos.kendoui.com/web/treeview/dragdrop.html

Resources