You can use pop-over to display a list. In the pop-up window, you can create a table view to display a list of elements, and when the user selects any option, didSelectRowAtIndexPath will be called, from this method you can send the selected value and display it in a label.
Code in mainviewcontroller where you want to display a dropdown.
if (m_OptionController !=nil) { [m_OptionController release]; m_OptionController = nil; } m_OptionController=[[OptionViewController alloc]init]; [m_OptionController setTarget:self andSelector:@selector(displaySelectedOption:)]; if(m_pPopOverController) { [m_pPopOverController dismissPopoverAnimated:YES]; [m_pPopOverController release]; m_pPopOverController=nil; } m_pPopOverController=[[UIPopoverController alloc]initWithContentViewController:m_OptionController]; [m_pPopOverController setPopoverContentSize:CGSizeMake(thePopOverFrame.size.width, thePopOverFrame.size.height) animated:NO]; [m_pPopOverController presentPopoverFromRect:CGRectMake(theButton.frame.origin.x,0,40,40) inView:self permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
OptionViewController is a UIViewController that will contain a UITableView.Populate a UITableView with data (list of options).
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if ([m_Target respondsToSelector:m_Selector]) { [m_Target performSelector:m_Selector withObject:nil]; } }
Remember to set a goal by calling this method, so when the user selects any option, the corresponding method in the mainviewcontroller is called where you want to select the value.
- (void)setTarget:(id)inTarget andSelector:(SEL)inSelector { m_Target = inTarget; m_Selector = inSelector; }
source share