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 s开发者_运维百科een in iBooks when you select PDFs/Books.
I have a slight idea how to implement it, just correct me if I am wrong:
- Create the button
- On a click event of the button define a
CGRect
and within theCGRect
draw aLoadTableView
- Load
TableViewData
at runtime.
Is that correct? If not, how should I do it?
Here's a much better/easier way to do it.
- Create custom UITableViewController and associated nib. Use this class to encapsulate your tableView and data.
- When the user clicks on your button, instantiate your custom view controller and display it modally using presentModalViewController:animated
- When the user has selected an option from your popup view, call back to the parent view with the results.
- Dismiss your table view with dismissModalViewControllerAnimated:
This is what iBooks does with a highly customized UITableViewController.
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.
精彩评论