How to use collapse option to display list of users - ios

How to design and code this in swift(IOS) AND Xcode.If we tap on down button it should display items and vice-versa like this:

You need a Collapsable TableView. In order to achieve that, in your TableView you must keep track of which sections are collapsed (contracted) and which of them are expanded. For this you need to maintain a set of indices of sections that are expanded, or a boolean array where the value of each index indicates if the corresponding section is expanded or not. Check for the values at the specific index while assigning height to a certain row. Check this link for more help.
Refer ans by #Cristik.Refer my previous ans for more info.

You need expandable table view. Basically, you need to control the open and close of sections of your table view.
Here is an good example with working code & animation written in swift 3.0

Related

Accordion for UIView and SubViews in Swift 3

I'm trying to build an accordion style ( expand/collapse ) list in IOS/Swift 3. Was confused on which approach to follow like a static UITableView ( since my sub divisions have different types of Ui Controls in the cells ie some have checkbox ,spinner, textview etc. with labels to show configure a list of different Valves) , UIView with nested UIViews sections with an option to clip views . But both have been messed up with without any success.
Illustration
http://imgur.com/a/Bs9SF
Below are the links I followed
https://github.com/justinmfischer/SwiftyAccordionCells
http://www.appcoda.com/ios-static-table-view-storyboard/
https://github.com/Weebly/TableSchemer
https://github.com/Alliants/ALAccordion
Any other approach without UITableView?
Please help . Thanks in advance .
Static vs dynamic table will depend on your data source. Does your data source for your table change? If so you'll want a dynamic table, if not then you can design it out in a static one.
As for the accordion feature, what I've done in the past is to add a tap gesture recognizer to the header view of each section. When the tap is detected I change my datasource and reload the table view. What happens is that number of rows for section is called on reload, and I return 0 so that none of the rows show. When tapped again you can go back to showing the normal number of rows.
To get the animation you need to use delete rows with index paths and animate it.

Design event view using swift

i want to make a view for event details, using swift, something like this one:
what do you suggest me to use? tableview? collectionview? every events has a different numbers of rows and every row can have a different height, example based on text.
Is there some example on the web?
Thanks!
I suggest a tableView and everything row should be in section.
Sections:
image section
action section
date section
and so for forward. For the sections you can use and enum so you don't use directly ints. Then every section has one row usually. The final design should result pretty clean.

Insert cells into a section of an already statically created table

I am creating an iOS app that has a form to create a certain 'event'. This form is wrapped in a tableview. This tableview consists of static cells. But there is one section in the table that can be used to add persons to this event and thus on a button press a new tableview cell needs to be inserted at that section. To demonstrate this see the following image:
What I want to know is how to insert cells into a static table. And also how to grab them when the user submits the form, since, as far as I'm concerned, you can't grab a specific section of a table.
I already looked at this kind of concept but this does not apply on adding cells:
Mixing static and dynamic sections in a grouped table view
Thanks,
I think there are (at least) 2 workarounds for this:
You could add a dynamic UITableView as a child to the UITableViewCell. See this stack overflow question about this.
An other solution would be to bypass the table functionality in that cell and change the height of the cell and add the extra controls manually.
It's not possible to add or remove cells at runtime, you'll need to use a data source for your tableview. I asked a similar question here, with no luck.
In response to your second question, you can always grab cells using the cellForRowAtIndexPath: method on UITableView.

Toggle showing/hiding child table cells iOS

I'm trying to create a UITableview that contains STATES and CITIES. To start with, I'd like the table to display only the STATES, with each value having a downward facing disclosure arrow on the right hand side of the cell which lets the user know it has values underneath it. If the user clicks the arrow, the table would expand to show the CITIES associated with the selected STATE. The user could then either select a CITY, or click on a upward facing disclosure arrow which would then "hide" the CITIES.
I've downloaded and reviewed Apples "Table View Animations and Gestures" example.
I was hoping someone might know a simpler way of accomplishing what I'm asking for.
http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
Good Job on explaining exactly what you want to do. This is how I would tackle this, I figure it would be easier to explain it without giving you meaningless code and answer any coding concerns you might have after.
I would set up the table view data source to be an array of arrays. The idea would be that every index in the array would represent a state and therefore contain a number of cities, hence ever index contains an array (array of cities). The parent array(of states) will be empty at the beginning, but the arrays(of cities) that will later fill it would be populated with the appropriate cities.
I would then set up the table view to contain sections (I a tempted to put code here, but read along). The sections would represent the cities. You can then fill out the table view with sections using (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section delegate. On the first run you can fill the actual table with one cell per section (maybe with the word "expand" or "more" and your down arrow). When the user touches that cell you can use the didselectrowatindexpath to know which section was touched (the indexpath object contains the section), now that you know which section it is, just modify the data source by adding the array of cities for that section of the array of arrays (parent array) and update the tableview.
This essentially gives your tableview an according style and feel. It is very easy to implement but requires a little bit of code. I have done this and am willing to provide the code you might need, the trickiest part would be to update the tableview in the correct way.
EDIT CODE:
I did a simple example following above explanation. The code is on Github , feel free to ask any questions about it.
I think a better way to represent this information would be to have a UITableView containing the states with each state showing a tiny arrow pointing to the right. Then, when a user clicks on the state, load the next UITableView that shows all of the cities in that particular state. Using a UIViewController for pushing the City list will allow users to easily return to the States list.
This approach will make much more sense to iOS Users, because this is how they expect Tables to work.
There are many tutorials explaining how to use UITableView. Here is a link to a site with many UITableView tutorials. The tutorial I linked to explains pushing a UIViewController on to the stack so that there is a simple back button back to the State list.
Normally such thing is done by seguing to another view and showing more details about cell.
What you want you could achieve by actually making custom UITableViewCell which would contain UIButton with arrow image and UITableView. In case button is clicked for the first time you could reload your cell and create inner UITableView which could show cities. Another click would simply reload cell again and not return inner UITableView at all. You also need to keep selected state somewhere because you may have to reload previous cell and hide inner table in case arrow in other cell is clicked.

Getting data from a custom cell

I am dealing with a problem when I try to get my data from custom cell which has two different textfields.
The custom cell was implemented this way:
http://imageshack.us/photo/my-images/441/screenshot20120726at434.png/
And the table view looks like this:
http://imageshack.us/photo/my-images/849/screenshot20120726at431.png/
What I want to do is that when I press SAVE button from the right top corner I should get the values from the two textfields and also the switch status. I don't know how to manage the cells in order to do that. Thank you in advance!
You can create three index paths with section 0 and rows 0, 1, and 2. Then ask your table view for cellForRowAtIndexPath:. You know which type of information you want from each -- the same as what you stored in your datasource method -- and can read it from the matching text field or switch.

Resources