Reputation: 1922
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.
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. 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? 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!
Upvotes: 0
Views: 576
Reputation:
What you wrote in the comment does work. The 2 methods you would need, are the following:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
self.rowHeight = ...;
[tableView beginUpdates];
[tableView endUptates];
}
and
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
if (indexPath == selectedCellIndexPath)
{
return self.rowHeight;
}
return ...
}
Edit
If you want to change the text of the label, you can do like this:
[self.myLabel setText:@"Your new Text"]
Upvotes: 1