Submenus in UITableView - ios

I am building an app that uses a side menu, within that side menu is a UITableView displaying some text. When you click on one of those, it takes you to another ViewController. I searched the internet for it but didn't find something useful. My question is: how to make a "submenu" inside the tableview, so that when you click on it, it needs to dropdown and show more options.
I don't have any idea how to do this, so a little help would be really appreciated!
Thanks

You may use sections for building a submenu structure. You can overwrite viewForHeaderInSection for each section for which you don't want to display the section header and return an empty UIView object with a size of (0.0, 0.0) or even null. (I never tried returning null/nil myself.)
For each menu on the highest level you have exactly one corresponding section and each of them has just one row. They may or may not have header views.
For the menu that you want to display as submenu you set the header view of the related section accordingly and then have one row for each item of the submenu.
Unfortunately this allows for a 2-level menu heirachry only. But on the upside everything you need is already sort of build-in into cocoa touch.

Perhaps this could possibly help you achieve what you are looking for:
Expandable Sections UITableView IndexPath SWIFT
You may have to have a good look through the code but it should set you on the right track.

Related

Swipe to delete on entire section in UITableView

I have a UITableView which has a variable amount of sections and every section has a variable amount of rows. Every section contains a section header, a section footer and the rows for that section. They are shown and displayed inside a container. Everything up until now works as expected. To demonstrate what my UITableView currently looks like:
I am now trying to implement the possibility to swipe left on the entire section, so that the header of the section, the rows inside this section and the footer of this section move to the left and display another UIView. I am capable of swiping the cells separately, but enabling this feature on the entire sections have caused headaches for the past two days. This is what I would like to achieve:
I have thought about implementing UIGestureRecognizers but I am afraid they might conflict with my UITableView. Also, I started implementing it, but I would not know how to move solely the section on which was swiped to the left.
Then I thought I could maybe implement a UIScrollView as container for each section. How I would accomplish this is still a mystery to me, but it seems like a possible solution if this could be done.
Furthermore I am out of ideas and stuck on how this should be done. It's something I have not found on the Internet so far - at least no working examples of some kind so I have zero inspiration on how to achieve the effect.
I therefor would like to ask if somebody has an idea of how this could work and what I have to keep in mind when implementing this. Every clue pointing me towards a working solution is gratefully appreciated!
EDIT: I have already seen the possible duplicate this afternoon. However, the suggestion there shows touchesBegan() on the header, which does not work in my case as I need the entire section to be "draggable".
I think one way you can implement this is with a vertical stackview containing views that contains a tableview and the trash icon. When a user swipes left on the tableview header, it will show the hidden trash icon in the view. I would think that each tableview only has one section so it will be easier to keep track of which "section" the user has swiped.
I have currently managed to arrange a similar solution. I take the rectangle of the section with rect(forSection:int), add a UIPanGestureRecognizer in which I add a UIView on top of the UITableView if touches began, I calculate the location of the finger and let the cudtom UIView follow. When a certain point (100 from left edge of the UITableView) is reached, the section gets removed with deleteSections(indexSet:with:).
This works. It does the job, but it adds an overlay to the section rather than pushing it to the left.
Therefor I am asking of someone knows if there is any way of setting the offset for one specific section or for an area of a UIView, so I can offset the rectangle of the section. I have been able to setContentOffset on the entire UITableView but this is not the desired result.
If there is no way to do this, I would consider keeping the solution I have now or maybe implement a snapshot feature which takes a screenshot and crops the rect of the frame, adding this UIImage to the custom view to simulate the section. But that would be tricky. Any ideas for this idea are also welcome.

TableView with bar to change content on top, how to build it?

I have to build a tableView with a top bar "slider" like the one in the youtube app in the picture below.
I just wanted to ask if it's better to:
Use just one tableView and switch the content by changing some switches in the delegates methods and reloading all the rows
or
Use two tableViews and hide the one that's not displayed
If none of the two methods above is the best one please point me in the right direction, thank you.
Option 1 :
Take a UISegmentView on the top and have a single UITableView. Change the content of UITableView on valueChange event of segment.
Option 2 :
Have look at this awesome library by Yalantis - Segmentio. I have myself used this on couple of occasions. Handy when you have to horizontally scroll the segments (exactly what you need in your case). You can have a single UITableView for this as well.
Option 3 :
Check out another useful library by Yalantis - Persei. Just hard scroll the table to see these options. Again, single UITableView.
In all, the best solution, in my opinion is to have a single UITableView. Working with multiple tableView might seem a clean way for a start, but trust me, maintainability is the key and having a single UITableView would be a better approach.

How to implement scroll-then-fix items in iOS?

I have a problem but I don't know what keyword should I use to indicate this issue.. so I named it scroll-then-fix.
What I want to do is make element behave as below
It scrolls up and down with other contents
When scrolling up, when it reaches the top of the screen, it does not go up anymore and stays at the top, while other contents continuously scrolls up.
For example, when you click any app in app store, the segmented control in the middle act like this.
I have no idea and I don't know what keyword I should search in google to find any information (I don't even know what this is called).
Please help me or give me a hint.
Thanks in advance.
How I would do that effect from the app store is that I would have a UITableView with 2 sections. The first would contain no section header and only one cell (containing the app icon, app name and "GET" button), and the second section would have a section header (containing the segmented control) which will stick to the upper side of the screen. The second section cells would contain the app screenshots, description etc.
Plain style UITableView's header behaves like that. Try it.

change order of list in tableview by clicking on whole cell

I currently have a 'tableview' with a list of items and I have enabled an 'edit' button to go into edit mode which shows the 'reordering controls' on the right side of the screen. I have also enabled 'canMoveRowAtIndexPath' and 'moveRowAtIndexPath:toIndexPath' to allow for the user to hold and drag the reorder control on the right side to reorder the list and have the data model update.
Is there a way to enable this but allow the user to click and drag the whole cell and not only the 'reorder controller'? Essentially I want to enlarge the area of the reorder controller's function to the whole cell when tableview is in editing mode.
for anyone else who is interested, I used this guide to get it working: b2cloud
the starting code template does not work as optimally since it has nib files and I'm using Xcode5 but it still works. The important code is all in the actualy tutorial as he lists how to set the reorder control to the size of the size via inserting it as a subview.
There is a way to enable this that allow the user to click and drag the whole cell and not only the 'reorder controller'!
Please check it out: https://github.com/FlorianMielke/FMMoveTableView
This might be helpful to you, Sir :)

ios cocoa: How to adjust the size of the popover depending on the number of rows in uitableview

This is related to this question
ios filter options similar to the apple store (dropdown list)
I tried using a uitableviewcontroller instead of a pickerview as I couldn't understand how to use the picker view if I need it popping out (any info on it would be appreciated).
Now this is what I did.
I have a VC that calls out a "FilterVC". I only have one FilterVC that is called by 3 different "filter buttons", and I will just populate the VC depending on the button. The issue is, one button might have just 2 items that is needed to be shown, another one might containg up to 50. Was wondering how do I adjust the height of the popovercontroller that contains the uitableview? Also, is this the right way in dealing with popovers, 3 segues connected to one VC??? (It needed an anchor point)
Here's what it looks like
As a follow up question:
Is this the right way to do it on an ipad? I feel like most people prefer the uipicker. The guy that answered my first question said it's more of a design thing. Now since I'm no designer, as a user, do you think uitableview is more appealing?
Thanks for your time!!
In the view that you're showing in the popover, set self.contentSizeForViewInPopover as soon as you know the size and before the view is displayed.
The main benefit of using a table view over a picker is that it has a scroll indicator so you can see how long the list of options is. Also obviously that you can control exactly how the list is displayed. So the table view should be better if it fits in with your UI style and particularly if the list of options is long.

Resources