我有一个名为的主视图控制器,TestViewController它有一个按钮,当您点击该按钮时,它会打开一个弹出视图控制器。当您点击背景时,弹出窗口会消失,这就是我想要禁用的。我的弹出视图控制器中有这段代码,它应该运行,但没有运行。
extension TestViewController: UIPopoverPresentationControllerDelegate {
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
print ("TEST") //This does not show up in console
return false
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
这是我用来打开弹出窗口的代码。
let popover = storyboard?.instantiateViewController(withIdentifier: "PopoverVC") as! PopOverViewController
popover.modalPresentationStyle = .popover
popover.popoverPresentationController?.sourceView = self.view
popover.popoverPresentationController?.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
popover.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
popoverPresentationController?.passthroughViews = nil
popover.dimView2 = self.dimView2
dimView2.isHidden = false
self.present(popover, animated: false)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用此处找到的 Eureka Swift 表单库。
我有一个文本字段,每当您开始输入时,我都希望隐藏表单的其他部分。我一开始只是试图隐藏 1 个部分,但是当我开始在该字段中输入时没有任何反应。我的代码如下:
form +++ Section("Device Search")
<<< IntRow()
{
$0.title = "Asset Tag"
$0.placeholder = "Enter Asset Tag #"
}
.onChange { row in
self.form.sectionBy(tag: "iOS Version")?.hidden = true
}
+++ Section("iOS Version")
for version in countArray
{
form.last! <<< CheckRow()
{
$0.title = version
$0.tag = $0.title
}
}
Run Code Online (Sandbox Code Playgroud)
另外,有没有办法使用 IntRow 但只删除该行的格式化程序?
我目前正在使用以下代码来过滤数组并将结果显示在我的 tableView 中。问题是,只有当搜索与确切的单词匹配时,才会返回结果。如何更改数组过滤器以在输入时搜索每个字符?
let data = ["Mango", "Grape", "Berry", "Orange", "Apple"]
var filteredData: [String] = []
filteredData = data.filter({$0 == searchBar.text})
Run Code Online (Sandbox Code Playgroud)
让“Mango”显示在我的 tableView 中的唯一方法是,我必须在搜索栏中输入 Mango,输入“Man”不会显示任何结果。
我有以下两个数组:
let xaxis = ["monday", "tuesday", "wednesday", "thursday", "friday"]
let yaxis = [1, 2, 3, 4, 5]
Run Code Online (Sandbox Code Playgroud)
我想将它们合并到一个如下所示的数组中:
[ ("monday", 1), ("tuesday", 2), ("wednesday", 3), ("thursday", 4), ("friday", 5)]
Run Code Online (Sandbox Code Playgroud) 我的AppDelagate中包含以下代码块:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
if response.actionIdentifier == UNNotificationDismissActionIdentifier {
print ("Message Closed")
}
else if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
print ("App is Open")
}
// Else handle any custom actions. . .
}
func showMessage()
{
let notification = UNMutableNotificationContent()
notification.title = "Test"
notification.subtitle = "This is a test"
notification.body = "I need to tell you something, but first read this."
notification.categoryIdentifier = "TESTAPP"
notification.sound = UNNotificationSound.default()
let notificationTrigger …Run Code Online (Sandbox Code Playgroud) 我正在使用此处找到的图表框架。
我的图表如下所示:
我的左图在第一个条形图下有一堆值,而我的第二个图在第二个条形图下缺少一个值。我设置图表的函数如下:
func setChart(chartview: BarChartView, xarray: [String], yarray: [Double]){
var dataEntries: [BarChartDataEntry] = []
for i in 0..<xarray.count {
let dataEntry = BarChartDataEntry(x: Double(i), y: Double(yarray[i]))
dataEntries.append(dataEntry)
}
let chartDataSet = BarChartDataSet(values: dataEntries, label: "")
let chartData = BarChartData(dataSet: chartDataSet)
chartview.xAxis.valueFormatter = IndexAxisValueFormatter(values:xarray)
chartview.xAxis.labelPosition = .bottom
chartview.chartDescription?.enabled = false
chartview.rightAxis.enabled = false
chartview.legend.enabled = false
chartview.data = chartData
}
Run Code Online (Sandbox Code Playgroud)
我使用相同的函数来创建其他图表,它们显示得很好,但由于某种原因有时它们显示为这样。
更新:
下面是每个图运行时的两个数组:
图一:
["iOS 10", "iOS 9"]
[67.0, 19.0]
Run Code Online (Sandbox Code Playgroud)
图2:
["2.1.0.6", "2.1.0.5", "2.0.32", "2.0.30", "2.0.23", "1.3.2.8"]
[67.0, 7.0, …Run Code Online (Sandbox Code Playgroud) 我正在快速寻找一个简单的解决方案,以添加点击屏幕上任意位置并关闭键盘的功能。我在这里阅读了很多答案,但它们都为我抛出了错误。我之前用过的一个是这样的:
override func viewDidLoad() {
super.viewDidLoad()
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target:self, action: #selector(ViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
Run Code Online (Sandbox Code Playgroud)
这适用于我的一个项目,但似乎不适用于任何其他项目。每当我尝试将其添加到其他项目时,我都会收到错误类型“ViewController”没有成员“dismissKeyboard”。
我正在使用此处找到的图表库。
我有一个图表,将每个条形标签显示为双精度,例如 15.0 而不是 15。我听说您必须使用 valueFormatter 来更改值,但不确定如何实现它。到目前为止我有:
let format = NumberFormatter()
format.numberStyle = .none
let formatter = DefaultValueFormatter(formatter: format)
BarChartData.setValueFormatter(formatter) // error here
Run Code Online (Sandbox Code Playgroud)
我正进入(状态:
实例成员 setValueFormatter 不能用于 ChartData 类型
swift ×8
ios ×2
arrays ×1
eureka-forms ×1
ios-charts ×1
keyboard ×1
swift3 ×1
tuples ×1
uisearchbar ×1