0
我首先構建了一個沒有筆尖的普通自定義單元,它的工作完美。但是現在我需要在各種視圖中重複使用相同的單元佈局,所以我試圖用一個筆尖代替普通的原型單元。 單元顯示內部信息。但我無法與之互動。例如,我不能在文本字段中寫入。當我點擊時,它只是選擇整個單元格(儘管我關閉了tableview選項中單元格的選擇)。Swift 2筆尖在uitableview加載但不會允許交互
我嘗試了不同的方式來初始化單元,但它崩潰或什麼都不做。
這是我的代碼:
CelluleView(自定義小區)
class CelluleView: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
override func awakeFromNib() {
super.awakeFromNib()
}
}
的ViewController
class PersoViewController: UITableViewController {
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
}
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "CelluleView", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "Cellule")
tableView.dataSource = self
tableView.delegate = self
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellule = tableView.dequeueReusableCellWithIdentifier("Cellule", forIndexPath: indexPath) as! CelluleView
return cellule
}
}
它的工作原理!但是它會圍繞文本字段居中,除非選中它們,否則我無法向下滾動到其他單元格。 我也在文本框旁邊添加了一個按鈕,但是我不能「點擊」它... – DRV
這讓我想知道你的觀點是如何設置的......我從來沒有遇到過這樣的問題。 – Moriya
當我遇到類似問題時,我通常使用本帖子中第二個答案中顯示的視圖層次結構工具 http://stackoverflow.com/questions/5150186/how-do-i-inspect-the-view-hierarchy- in-ios 這是一個很好的去檢查是否有任何視圖阻止觸摸或類似。 – Moriya