如何在iOS中创建多个值选择选择器?
答
你可以使用默认的UIPickerView与
//Objective-C
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
//Swift
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
定义多个值的行数。
你可以从这里看到的代码。
答
另一个从列表中选择多个值的选项是UITableView。 尝试以下代码并将选定的值保存在数组中。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}else{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
}
检查这个link,这太棒了。
答
以及选择多个选项
我建议使用泰伯维比pickerview因为pickerview唯一目的就是随便选一个。
简单的添加代码和额外的数组可以在桌面视图中执行作业