我正在尝试使用滑块和表格视图在Swift中制作简单的时间表应用(用于数字1-9)。我正在设法使滑块工作,并为每个使用滑块选择的数字创建一个数组,并且该数组显示在控制台上。我无法让数字出现在表格视图中。你能帮我,告诉我我错过了什么吗?无法在简单的时间表中显示表格视图数据应用
这是我到目前为止写:
class ViewController: UIViewController, UITableViewDelegate {
@IBOutlet var sliderValue: UISlider!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 9
}
@IBAction func sliderMoved(sender: UISlider) {
sender.setValue(Float(lroundf(sliderValue.value)), animated: true)
print(sliderValue)
var cellContent = [String]()
for var i = 1; i <= 10; i += 1 {
cellContent.append(String(i * Int(sliderValue.value)))
}
print(cellContent)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.textLabel?.text = cellContent[indexPath.row]
return cell
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
你提供的实际上不涉及任何的tableView也不成立的tableView的委托和数据源代码。此外,你的类坚持'UITableViewDelegate'协议,但实际上实现了几个'UITableViewDataSource'函数,这可能不会有太大的用处... –