2011-12-15 79 views
0

我需要实现一个按钮,它将显示在UIView或MKMapView的应用程序的右上角。点击该按钮后,组合应该出现,用户可以选择类别。带隐藏菜单的按钮iPhone

我该如何做到这一点?

+0

你想达到这样的目的吗? http://cocoacontrols.com/platforms/ios/controls/camera-flash-toggle – victorash 2011-12-15 13:41:53

回答

1

您必须创建一个UIButton并将其添加为UIView的子视图(例如,如果视图链接到UIViewController,则在viewDidLoad方法中)。

UIButton *showButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
showButton.frame = CGRectMake(500, 20, 150, 44); // hardcoded frame, not quite elegant but works if you know the dimension of your superview 
[showButton setTitle:@"Show Categories" forState:UIControlStateNormal]; 
// add target and actions 
[showButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
// add to a superview, your parent view 
[superView addSubview:showButton]; 

然后添加一个方法,称为buttonClicked:接受一个I​​D参数(通常是发件人,showButton在这种情况下)。

-(void)buttonClicked:(id)sender 
{ 
// visualize categories 
} 

形象化的类别,你可以按照两种不同的方式:

  1. 呈现UIPopoverController(仅适用于iPad设备)
  2. 显示一个模态控制器呈现一个UITableViewController(包括iPad和里面的UITableViewController iPhone设备)。

UITableViewController允许你有一个类别列表,然后选择其中的一个。

P.S.检查XCode中的代码是因为我手写的(没有XCode)

+0

thanx flex,单元格视图的想法如何,其中单个行将可见并单击该行将显示隐藏行选择类别?将这项工作.. 我想实现你的建议 – AppDeveloper 2011-12-15 14:44:24