在我的应用程序中,我想添加一个步进器,以便用户可以将值从 1 增加到 100。
我可以让步进器显示,我已经添加了动作,但表格视图中的标签没有刷新......每次用户点击步进器时我是否需要执行“self.tableView.reloadRowsAtIndexPaths”?
class SettingsOptionTableViewCell: UITableViewCell {
@IBOutlet weak var labelvalueforstepper: UILabel!
@IBOutlet weak var simpleStepper: UIStepper!
@IBOutlet weak var labelwithStepper: UILabel!
}
class SettingOptionsTableViewController: UITableViewController {
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
cell = tableView.dequeueReusableCellWithIdentifier("SettingOptionsCell3") as! SettingsOptionTableViewCell
cell.labelwithStepper.text = "Value:"
cell.simpleStepper.value = 1
cell.labelvalueforstepper.text = (cell.simpleStepper.value).description
cell.simpleStepper.wraps = false
cell.simpleStepper.autorepeat = true
cell.simpleStepper.maximumValue = 100
cell.simpleStepper.addTarget(self, action: "stepperValueChanged:", forControlEvents: UIControlEvents.ValueChanged)
}
func stepperValueChanged(sender: UIStepper) {
let pointInTable: CGPoint = sender.convertPoint(sender.bounds.origin, toView: self.tableView)
let cellIndexPath = self.tableView.indexPathForRowAtPoint(pointInTable)
if let myRowSection = cellIndexPath?.section {
if let myRow = cellIndexPath?.row {
var device_status: Int = Int(sender.value)
println(sender.value)
println(myRow)
segmentDeviceViewValueChange(myRow, userSelection: device_status)
let cell: SettingsOptionTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("SettingOptionsCell3", forIndexPath: cellIndexPath!) as! SettingsOptionTableViewCell
cell.labelvalueforstepper.text = device_status.description
}
}
}
}