“使用未解析的标识符”SWIFT

时间:2016-01-30 08:36:01

标签: swift

错误

  

使用未解析的标识符'slider'

来自

  

var sliderValue = slider.value

有什么问题?

 import UIKit

    class ViewController: UIViewController {

        @IBAction func colorChanger(sender: UISlider) {
            // creates variable to hold new color
            var newBackgroundColor : UIColor

            // creates variable holding the value from slider
            var sliderValue = slider.value

            // changes the newBackgroundColor variable to new color values.
            newBackgroundColor = UIColor(hue: sliderValue, saturation: 0.5, brightness: 0.5, alpha: 0.5)

            // changes the background color
            self.view.backgroundColor = newBackgroundColor    }

2 个答案:

答案 0 :(得分:1)

就我(或Swift ;-))所见,你的代码中没有定义slider属性。

相反,您的方法中有一个名为sender的参数是UISlider,因此请尝试使用该参数。

var sliderValue = sender.value

sender重命名为slider

所以这是一种做法(在@ leo-dabus的帮助下)。我冒昧地清理你的代码,抱歉: - )

import UIKit

class ViewController: UIViewController {

@IBAction func colorChanger(sender: UISlider) {
    // creates variable holding the value from slider
    let sliderValue = CGFloat(sender.value)

    // changes the newBackgroundColor variable to new color values.
    let newBackgroundColor = UIColor(hue: sliderValue, saturation: 0.5, brightness: 0.5, alpha: 0.5)

    // changes the background color
    view.backgroundColor = newBackgroundColor    
}

答案 1 :(得分:0)

我为你的问题找到了解决方案

首先勾住滑块

Imports System.Data

Imports System.Data.SqlClient

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim MyConnection As System.Data.OleDb.OleDbConnection
            Dim DtSet As DataSet
            Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
            Dim Loc As String = Application.StartupPath() + "\Param\exceldata.xlsx"
            Dim strCOleCon As String = "provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + Loc.Trim + "';Extended Properties=Excel 8.0;"

            MyConnection = New OleDb.OleDbConnection(strCOleCon)
            MyCommand = New OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
            MyCommand.TableMappings.Add("Table", "TestTable")
            DtSet = New DataSet
            MyCommand.Fill(DtSet)
            DataGridView1.DataSource = DtSet.Tables(0)
            MyConnection.Close()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

End Class

然后在storyboard或xib或编程中设置最小值,最大值和当前值

@IBOutlet var slider: UISlider!

输出

let sliderValue = Int(slider.value)
print("Slider value is now - \(sliderValue)")