Dumb Code
Dumb Code

Reputation: 438

Present a UITableView as drop-down list using the iOS SDK

I want to implement a drop-down list in an iPhone application, the same like you might have seen in iBooks when you select PDFs/Books.

I have a slight idea how to implement it, just correct me if I am wrong:

  1. Create the button
  2. On a click event of the button define a CGRect and within the CGRect draw a LoadTableView
  3. Load TableViewData at runtime.

Is that correct? If not, how should I do it?

Upvotes: 2

Views: 7339

Answers (2)

marzapower
marzapower

Reputation: 5611

Are you looking for a UIPickerView?

This component gives you the possibility of selecting from a custom number of elements through a dedicate table view. Use it in conjunction with a UIActionSheet to get the best results.

Upvotes: 0

kubi
kubi

Reputation: 49364

Here's a much better/easier way to do it.

  1. Create custom UITableViewController and associated nib. Use this class to encapsulate your tableView and data.
  2. When the user clicks on your button, instantiate your custom view controller and display it modally using presentModalViewController:animated
  3. When the user has selected an option from your popup view, call back to the parent view with the results.
  4. Dismiss your table view with dismissModalViewControllerAnimated:

This is what iBooks does with a highly customized UITableViewController.

Upvotes: 2

Related Questions