当我点击dropdown按钮时,我想要像listview那样的dropdown列表,并使列表包含一些内容。然后,我选择的任何内容都将是标签的文本,任何人都可以帮助我。谢谢你。
发布于 2012-06-04 18:45:28
您可以使用弹出窗口来显示list.In弹出窗口,您可以创建tableview来显示项目列表,当用户选择任何选项时,didSelectRowAtIndexPath将被调用,通过此方法,您可以发送选定的值并在标签中显示。
mainviewcontroller中的代码,您想要显示下拉列表的位置。
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是一个UIViewController,它将包含带数据的UITableView.Populate UITableView (选项列表)。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([m_Target respondsToSelector:m_Selector]) {
[m_Target performSelector:m_Selector withObject:nil];
}
}不要忘记通过调用这个方法来设置目标,所以当用户选择任何选项时,mainviewcontroller中的相应方法会被调用到您想要选择的值的位置。
- (void)setTarget:(id)inTarget andSelector:(SEL)inSelector
{
m_Target = inTarget;
m_Selector = inSelector;
}https://stackoverflow.com/questions/10879979
复制相似问题