![](/img/trans.png)
[英]UITableView Custom Cell Auto scroll when text field is tapped : Swift 3
[英]Trigger an action when cell in static UITableView is tapped [Swift]
我在桌面視圖中有八個不同的靜態單元格。 我試圖用六個單元格執行不同的操作。 其中兩個打開一個警報視圖,兩個打開safari,一個清除緩存,最后一個打開一個共享彈出窗口。 以前,他們都與UIButtons和IBActions合作。 但是自從設置靜態tableview以來,我遇到了問題。
我正在嘗試將各個單元格連接到自己的行為中,而我似乎無法通過插座來實現這一點。 我怎么能這樣做?
謝謝。
斯威夫特3
表格視圖代碼:
import UIKit
class AltSettingsTableViewController: UITableViewController {
@IBOutlet weak var copyrightInfo: UITableViewCell!
@IBOutlet weak var shareApp: UITableViewCell!
@IBOutlet weak var rateApp: UITableViewCell!
@IBOutlet weak var clearCache: UITableViewCell!
@IBOutlet weak var purchasePhotos: UITableViewCell!
@IBOutlet weak var helpFeedback: UITableViewCell!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.backgroundColor = UIColor.clear
self.tableView.backgroundView = nil;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.minimum(35, 35)
}
override var prefersStatusBarHidden: Bool {
get {
return true
}
}
你有沒有重寫func tableView(UITableView, didSelectRowAt: IndexPath)
? 它應該讓你知道什么時候點擊一個單元格然后你可以使用indexPath
來確定它是哪個單元格。
編輯: UITableViewDelegate和NSIndexPath的文檔。
例:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
// do stuff
}
//...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.