Dinesh Kumar
Dinesh Kumar

Reputation: 1293

How to show the TableView (like dropdown) on Button Click in iPhone?

I have tried this code. http://www.mediafire.com/download/bvoqrkn82sd6az9/tablesample.zip ..Here, It will display the Table View. But I need to create a tableview whenever I click the button, it should display the list of Tableview like dropdown as it is in this screenshot. http://www.mediafire.com/download/7jiwb0e00916gh9/Table+View.PNG This is what I need to display. Your help is highly appreciated. Thanks in advance.

enter image description here

Upvotes: 3

Views: 13718

Answers (3)

Dushyant Singh
Dushyant Singh

Reputation: 721

I have implemented this , You can achieve this by adding the button on the first row of any section and load other rows by the click on the first row with UITableViewRowAnimationTop using beginUpdate.

So now every first row of the section with index==0 will be a dropdown button and other rows starting from index=1 will be your data rows representing the information.

Upvotes: 0

Krishna Kumar
Krishna Kumar

Reputation: 1652

You can change height of tableView with animation. Set time according your suitability.

For Expansion:

[UIView animateWithDuration:1
                              delay:0.0
                            options: UIViewAnimationYourChoice
                         animations:^{
                            CGRect frame = self.tableView.frame;
                              frame.size.height = 300;
                             self.tableView.frame = frame;
                         }
                         completion:^(BOOL finished){
                             NSLog(@"Done!");
                         }];

For shrinking:

[UIView animateWithDuration:1
                              delay:0.0
                            options: UIViewAnimationYourChoice
                         animations:^{
                            CGRect frame = self.tableView.frame;
                              frame.size.height = 0;
                             self.tableView.frame = frame;
                         }
                         completion:^(BOOL finished){
                             NSLog(@"Done!");
                         }];

Upvotes: 3

TamilKing
TamilKing

Reputation: 1643

There is no option for dropdwon in IOS SDK. If you need this follow like this.

  1. On the click of this button you'll have to load a UIView or UITableView which will come exactly down to your UIButton.
  2. This custom UIView or UITableView will act as your drop down.
  3. Once your use is complete you can either hide it or remove it.

I hope it will hepl you.. Instead of dropview you can use UIPopoverController to show the UITableView

Upvotes: 1

Related Questions