- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
func popUpList(title: String, PickerList: [String],index: Int, complistionHandler: @escaping (_ selectedValue: Int) -> ()) {
let alertController = UIAlertController(title: nil, message: "\n\n\n\n\n\n\n", preferredStyle: .alert)
alertController.isModalInPopover = true;
let picker = UIPickerView(frame: CGRect(x: 0.0, y: 0.0, width: 250, height: 250))
picker.delegate = self
picker.dataSource = self
picker.selectRow(index, inComponent: 0, animated: true)
picker.showsSelectionIndicator = true
list = PickerList
picker.reloadAllComponents()
alertController.view.addSubview(picker)
let ok = UIAlertAction(title: "Ok", style: .default) { (alert) in
print(picker.selectedRow(inComponent: 0))
complistionHandler(picker.selectedRow(inComponent: 0))
}
alertController.addAction(ok)
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancel)
self.present(alertController, animated: true, completion: nil);
}
此代码始终返回值 = 3。但我想获取已选择的索引值。请在这里帮助我
最佳答案
我试过你的代码。原来你的选择器太大了,它的背景是透明的,而且它在你的按钮前面,所以它拦截了所有的触摸。如果减小 Y 大小,则不再冲突。同样,如果您添加更多新行,它会起作用。此外,如果您将选择器发送到按钮后面,它也可以工作。如果你使用 View 调试器,你可以看到选择器的范围,你可以告诉它重叠,它在按钮前面。此代码有效:
import UIKit
typealias PopUpListCompletionHandler = (Int) -> (Void)
class ViewController: UIViewController {
fileprivate var list = [String]()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
popUpList(title: "Pick a number from 1 to 10", PickerList: stride(from: 1, to: 11, by: 1).map {"\($0)"}, index: 5) { index in
print ("You picked index \(index) which has a value of \(self.list[index])")
}
}
func popUpList(title: String, PickerList: [String],index: Int, completionHandler: @escaping PopUpListCompletionHandler) {
let alertController = UIAlertController(title: nil, message: "\n\n\n\n\n\n\n", preferredStyle: .alert)
alertController.isModalInPopover = true;
let picker = UIPickerView(frame: CGRect(x: 0.0, y: 0.0, width: 250, height: 200))
picker.delegate = self
picker.dataSource = self
picker.selectRow(index, inComponent: 0, animated: true)
picker.showsSelectionIndicator = true
list = PickerList
picker.reloadAllComponents()
alertController.view.insertSubview(picker, at: 1)
let ok = UIAlertAction(title: "Ok", style: .default) { (alert) in
completionHandler(picker.selectedRow(inComponent: 0))
self.dismiss(animated: true, completion: nil)
}
alertController.addAction(ok)
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alertController.addAction(cancel)
self.present(alertController, animated: true, completion: nil);
}
}
extension ViewController: UIPickerViewDelegate {
}
extension ViewController: UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return list.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return list[row]
}
}
关于ios - 它总是在 iOS swift 中返回相同的索引 "picker.selectedRow(inComponent: 0)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40044535/
我正在寻找一个使用 iCloud for Xamarin Form for iOS 的文件选择器库。目前我正在使用 FilePicker-Plugin-for-Xamarin-and-Windows用
我对选择器 View 有一些疑问我有两个选择器 View 选择器 View 1 = getpPlandateDCPlanData选择器 View 2 = getpShipmentDCPlanData
当我在运行 npm install 后克隆一个 angular 4 项目时,我有 angular-cli 1.5.6,当使用 ng serve 服务项目时,我得到了这个错误 ng2-日期选择器 ERR
当升级到 react-native 0.61.2 时,这个问题出现了。我做到了从手机中删除了 apk 和自动链接使用 react-native link 然后 react-native run-and
当升级到 react-native 0.61.2 时,这个问题出现了。我做到了从手机中删除了 apk 和自动链接使用 react-native link 然后 react-native run-and
Picker reference 4月24日更新。子类 DocsView 现在有一个函数 setEnableSharedDrives(),但是 Picker 抛出异常并且不显示 View 。 这是一个
我正在使用 DayPickerInput,我将其设置为 this (具有 2 天选择器输入的范围)。我想始终显示覆盖,我不想隐藏它。我知道 showOverlay Prop ,但它只在初始渲染期间显示
如何将类添加到 react-day-picker 的今天按钮? 从文档中似乎是可能的: http://react-day-picker.js.org/api/DayPicker#classNames
我正在尝试使用 react-native-picker-select 包。根据他们的文档,@react-native-picker/picker 是一个依赖项。但是.. 将此包添加到我的 RN 应用程
我正在开发一个 SwiftUI View ,其目的是允许用户输入美元金额。我想要一排七个轮式选取器,每个值都是数字 0 到 9。 以下代码有效,除了,当我尝试触摸并拖动数字列以滚动它时,我发现我的拖动
我正在尝试使用 react-native-picker-select 包。根据他们的文档,@react-native-picker/picker 是一个依赖项。但是.. 将此包添加到我的 RN 应用程
在屏幕上我有 UIDatePicker。如果有简单的选择器就简单了。可能是这样的: app.pickeWheels["my_id_picker"].adjustToPickerWheelValue("
我想更改标签 我的 ,例如当语言改变时,由另一个按钮 ( react-redux ) 触发。 key和 value应该保持不变,只有 label变化。 不幸的是结果是重新渲染(?)和selected
这是我的示例代码,在 Android 中我无法第一次选择第一个 Picker Item,我创建了一个虚拟项目所以我需要隐藏第一个字段。 this.setState({selectedValue: i
我正在使用 Google Picker Api。 Google Picker 显示正常,但是当我选择一个文件(选择一个文件并单击 Select 按钮或双击一个文件)时,我收到此警报:An embedd
我正在尝试将简单的 GMSPlacePicker 示例转换为 Swift 但是选择器会出现,但一旦从右到左的过渡完成,它就会立即消失。 // ViewController.swift imp
我确信有一种方法可以做到这一点,但我还不知道如何实现。 我想做的是添加一个 Picker 组件,但不是对项目列表进行硬编码,而是从服务中获取该组件,并将 Picker 绑定(bind)到我稍后可以填充
我正在尝试对这段代码进行快照测试: import React, { Component } from 'react'; import { Picker, } from 'react-native'
我将 Place Picker 添加到我的 android 应用程序中。当您知道要选择的地点的地址并填写研究栏时,它就会起作用。但是我希望用户可以在使用红色选择器时选择他选择的位置,而这部分不起作用。
我想知道是否有任何适用于 iOS 的简单 Facebook 照片选择器 Controller 可以显示 facebook 相册和他们的照片,并让用户从中挑选照片。类似于 iOS Facebook SD
我是一名优秀的程序员,十分优秀!