2012-05-27 68 views
2

是否有任何其他UI对象用于在不是选择器视图的变量之间进行选择?替代选择器视图

我对iOS开发非常陌生,我想创建一个应用程序,让用户填写表单。

要在一小组变量之间进行选择,例如“男性”或“女性”,“大学”,“高中”或“孩子”,我宁愿选择一个下拉列表,但唯一能找到的东西是选择器视图。问题在于选取器视图很大,当只有2或3个变量时似乎没有必要。

回答

3

在iOS中处理此操作的常用方法是将UITableViewController推入UINavigationController堆栈,每个选项一行。使用委托方法传回选定的选项。

如果你想显示已选定的选项,设置cell.accessoryType = UITableViewCellAccessoryCheckmark

0

我会用一个UISegmentedControl

http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UISegmentedControl_Class/Reference/UISegmentedControl.html

[NSArray arrayWithObjects: @"Male", @"Female", nil]; 
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; 
segmentedControl.frame = CGRectMake(35, 200, 250, 50); 
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; 
segmentedControl.selectedSegmentIndex = 1; 

// replace self.view with whatever your view is.. alternatively you can also add a UISegmentedControl with Interface Builder in your XIB file. 
[self.view addSubview:segmentedControl];