How to create a dynamic drop down within a table view? - ios

I need to create a tableview with at least two sections, transportation and hotel. Tapping on either one creates a drop down view showing info on 1 to n examples of the topic selected. You don't know in advance what data is going to be there so it has to be dynamic to present any number of results with some having lengthy descriptions below each example and some not. I've been racking my brain and I can't figure out how to do this. The dynamic nature of this makes it extra difficult. Here is a mock up of what it should look like: click here

Check out this Git-Repo. I am using it inside my app and its working quite well. You can also watch the tutorial for it: https://www.youtube.com/watch?v=22zu-OTS-3M&t=1s
Hope that helps!

Related

How to achieve similar layout to 365 Scores app in Swift? (Screenshot included)

I tried to achieve the below layout with a single tableviewbut failed.
The structure of the below screenshot is as follows:
Date (Today):
My subscribed lists (My Teams & Games):
League name:
Actual match (Looks like a Tableview cell)
Please note that each level of the structure is dynamic in count depending on the matches of the day.
I tried implementing this with a tableview but couldn't figure out how to create nested sections. For example, at the top level I tried to make the sections headerView to represent the date but then I was forced to make the rest of the strucure inside a cell which is not the case for the app in the screenshot.
I am assuming the actual matches are the tableview cells since they are the ones that are swipe-able?
Please help me with some ideas.
Thanks.
There are various ways to approach this... here are just two ideas:
As was mentioned in the comments on your other question - you really need to start working on it. If you run into specific problems, come back here with specific questions.

Need some advice whether to use static stable view or dynamic table for my project

I am exploring the development of my first iPhone app (Xcode and Swift 3) and I need some direction and advice. I have a need of a multiple level expanding and collapsing table. I've attached some screens of a web app I developed to help you understand where I am going. In my app there are main level items, which expand to show sub items, which expand to show the contents of that item. And not every sub item (when expanded) has the same elements. Some sub items have simple text fields while other items have questions with yes and no answer options. I am so green I don't even know where to start with pulling this off in an app. I have worked through some tutorials on expanding and collapsing dynamic cells but I am unaware if that is the best way because not all of my sub cells contain the same contents. Should I use static cells instead? Or is there a way to create cell templates (like include files in php) and call them in to the table and populate them when I need them? I am lost and need some direction. Any help you can give me would be greatly appreciated. I would love tutorials as well. I have a Lynda.com account if you are aware of tutorials there I should follow. Thank you!
one of the simple layouts
a different layout
I think this lib could help you.

iOS - What are best practices for view controller setup for a posts + comments data model?

Forgive me if this question has been asked elsewhere, I was having trouble finding similar questions.
So I have an app where I am displaying a list of posts, and each post has a list of comments, very similar to the way Instagram's home page is laid out.
Current implementation
The way I've implemented it, I'm using a single UITableViewController and I have an array of posts that back my data source. Each post object has it's own array of comment objects. In numberOfRowsInSection I iterate through the posts array and add up all the posts and comments to get the total number of rows. I have two UITableViewCell templates, one for posts and one for comments, and in cellForRowAtIndexPath and estimatedHeightForRowAtIndexPath (and really any function that does anything significant) I have to do a bunch of logic just to get the right model or view for the given index path.
Issues
This setup seems to work okay, but is really difficult to debug and add features to. Especially now that I am trying to implement Pusher updates from the server, I am running into a lot of issues with how complicated the model to view relationship is and how long it takes to update the model before the view can be updated.
Alternative Implementations I've considered
I started reading a little about UICollectonViews and was thinking about using the supplementary views to show comments and having only the posts be regular cells, but I'm not sure if that's actually how collection views work or if it would make this any easier. I've also considered using only one cell template for the post + comments that dynamically adds comment views to itself as necessary, but I'm not even sure that's possible.
Question
Is there an easier way to implement a posts+comments layout that is better suited to the way the data is laid out? This seems like a pretty common problem that's been solved by a lot of people so I'm hoping someone can point me to some best practices.
Edit: An example of what I mean. The part outlined in red is the comment section for the post, outlined in blue. Instagram seems to be making each post a section though, with the poster's name as a floating header, each post being it's own section seems like it would be easier to implement. I had initially tried to implement my app that way but ran into issues with making the section header much larger than default, maybe I should just change my design to better suit sections?
I guess your main problem is that you are using different cells for "sub entities". So each time you have to reload multiple cells when updating one entity.
It doesn't really make a difference whether you chose the table or collection view. (Depending on the layout, but I guess Instagram is a table view too)
To make your view handling better / easier you should create a cell that handles all the properties of your entity. And for showing all comments you should probably switch to a new view controller. Or you could use one section for one post. So you could just reload one section. The post could be the section header and the comments the cells in the section.
So you could access your cells easily. tableData[section].commments[row]. And then you could just insert a new row into the section when a comment is added.
I hope I understood your problem.

How to relate data to a specific row in a UITableView

What I basically want is to show the user's name in the first tableView but have a disclosure indicator (segue) to go to a second tableView which will show the history of the selected user. I know how to load data into a table and how to segue from one row to the detail table but I just don't know how to show different data for each user. I know this may be out of my scope of knowledge at the moment but I would like to give it a try.
1- What would be the best way to store the data for each user (history), an array per user?
2- How can I relate data to a specific user so it loads when the user's name is touched?
3- How can I capture the row being selected?
Any suggestions will be appreciated.
Honestly, you shouldn't worry about it being outside of your scope of knowledge, as that's how people learn. You will need to do some amount of work, however, and that part can be a little difficult.
Luckily, what you're trying to do is a very well documented function and Xcode even provides a template for master -> detail views.
Check out this wonderful tutorial by Ray Wenderlich on creating a simple master-detail application: http://www.raywenderlich.com/1797/ios-tutorial-how-to-create-a-simple-iphone-app-part-1
His other tutorials will also be immensely helpful to beginning iOS development: http://www.raywenderlich.com/tutorials

How can storyboard handle two segues for a table cell?

I'd like a master/detail kind of UI, but with the option of going to a different detail page depending on the data in the table cell. Can storyboards do this? If so, is there a tutorial or somewhere that explains? As an alternative, if I mix table cell types in the same table, can I define different detail pages that way?
Also, just an observation, does anyone find the Apple tutorials get very complicated very quickly? I'm having trouble trying to get through even with the first iOS app tutorial. So many control clicks and command drags and whatever and to non-intuitive targets. Like, who would expect a drag from a graphical element to a specific line in a source file? It doesn't make any sense.
I think what you're looking for is didSelectRowAtIndexPath. In the .m file for the view controller you have your UITableView on, whenever the user clicks a row, it will trigger the code in didSelectRowAtIndexPath. Typically, you have an if block that checks which row was clicked, and does different things (like display different detail views).
As far as detailed tutorials, I find YouTube to be the easiest to learn from, especially for simple or common tasks. If you search for "Master-Detail Xcode" on there, I'm sure you'll find tons of results ( http://www.youtube.com/watch?v=S_J_r8AKw0k I think was one of the ones I found useful).

Resources