mercredi 25 mars 2015

Static And Dynamic Table View In Xcode

I want it to implement a table view that works like a drop down menu or a limited expandable table view. An example of functionality would be like this:


Each main cell has a food category, Italian, Chinese, Thai, etc. The cell has a label (Italian) with a number right next to it like this: Italian (5), meaning that there are 5 Italian restaurants in your area (you're downtown or something). The cell will also have an accessory view pointing downward. When you tap the cell, the accessory view will point upward and a table view will be displayed below that cell (and above the next main cell "Chinese"). The table view displayed will show each restaurant (one in each cell) of that kind in your area; it will be like 150-200 pixels in height, and I need to be able to scroll through it. When I'm done scrolling through and looking at the restaurants, I can tap the main cell, "Italian (5)", and the view will disappear with the accessory view pointing down again.


Side question: Should the parent table view be dynamic because of this considering that the number of restaurants in each category would change whenever the table view is visited or refreshed?


My main question is this: How would I go about implementing this? I tried an expandable table view using some code from GitHub, but the problem with that is this method is only adding cells to the table. ALL the cells (restaurants) are displayed, thus pushing the main cells further downward. I need to display a table view that has a fixed height that a user can scroll through. Would I have to use something like a container view after each main cell, have it hidden, and only appear when the main cell is clicked? The only thing that's keeping me from trying this is that I do not know how to programmatically make a view (ex. container view) appear or be inserted after the main cell has been tapped and have it disappear after the main cell has been tapped again. Should I put the code to do that in this function of the table view controller?



(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath


On the other hand, I do not want to overcomplicate it if there is a simpler solution, so any advice on what the best method would be, would be greatly appreciated, thanks!




Aucun commentaire:

Enregistrer un commentaire