【发布时间】:2016-03-26 22:12:51
【问题描述】:
我正在为 Apple TV 制作一个 tvOS 应用程序,但我的 UITableView 有一些问题。
当我点击UITableViewCell 时,什么也没有发生。我正在使用targetForAction,但它似乎不起作用。
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.dataSource = self
self.tableView.delegate = self
}
let allData = ["Los Angeles","New York","San Fransisco"]
@IBOutlet weak var tableView: UITableView!
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return allData.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Default, reuseIdentifier: nil)
cell.textLabel?.text = "\(allData[indexPath.row])"
cell.targetForAction("buttonClicked:", withSender: self)
return cell
}
func buttonClicked(sender:AnyObject) {
print("button clicked!")
}
【问题讨论】:
-
您是否有从您的
UITableView的UITableCell:s(或其子类)到下一个视图的segue?通常,您通过情节提要执行此操作,并通过重载表视图控制器源中的prepareForSegue方法来准备与下一个视图的可能通信。
标签: swift uitableview swift2 tvos