【发布时间】:2015-06-05 01:44:36
【问题描述】:
我在默认的 KeyboardViewController.swift 中以编程方式为自定义键盘扩展创建了 UITableView,但由于某种原因,didSelectRowAtIndexPath 根本没有响应。我确保将表格和单元格的 userInteractionEnabled 设置为 true,并确保将 allowSelectionDuringEditing 设置为 true。 tableView 肯定已被填充,当我触摸它们时单元格会突出显示,但日志根本没有出现(当它上有断点时方法也不会中断)。
有人对我为了实现这一目标而搞砸了什么有什么想法吗?
class KeyboardViewController: UIInputViewController, UITableViewDelegate, UITableViewData Source {
var tableView: UITableView = UITableView()
//other setup
override func viewDidLoad() {
super.viewdidLoad
// other setup here
tableView.frame = CGRectMake(0, 0, 320, 160)
tableView.delegate = self
tableView.dataSource = self
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.allowsSelection = true
tableView.allowsSelectionDuringEditing = true
tableView.userInteractionEnabled = true
self.view.addSubview(tableView)
}
//delegate&datasource methods
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let sectionTitle = artistSectionTitles[section]
let sectionArtist = artists[sectionTitle]
return sectionArtist!.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.userInteractionEnabled = true
let sectionTitle = artistSectionTitles[indexPath.section]
let sectionArtists = artists[sectionTitle]
let artist = sectionArtists?[indexPath.row] as NSString
cell.textLabel?.text = artist
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 22
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: false)
println("You selected cell #\(indexPath.row)!")
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return artistSectionTitles[section]
}
func sectionIndexTitlesForTableView(tableView: UITableView) -> [AnyObject]! {
return artistSectionTitles
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return artistSectionTitles.count
}
【问题讨论】:
标签: ios uitableview swift didselectrowatindexpath