2016-12-23 49 views
1

我有八個不同的靜態單元格在tableview中。我正試圖用六個單元執行不同的操作。其中兩個打開警報視圖,兩個打開Safari,一個清除緩存,最後一個打開共享彈出窗口。以前,他們都使用UIButtons和IBActions。但是,自從設置一個靜態tableview以來,我遇到了一些問題。觸發靜態UITableView中的單元格時觸發一個動作[Swift]

我試圖將單個細胞連接到自己的行爲,我似乎無法與網點做到這一點。我該怎麼做?

謝謝。

斯威夫特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 
    } 
} 

回答

0

你有重寫func tableView(UITableView, didSelectRowAt: IndexPath)?它應該讓你知道什麼時候點擊一個單元格,然後你可以使用indexPath來確定它是哪個單元格。

編輯:文檔UITableViewDelegateNSIndexPath

實施例:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    if indexPath.row == 0 { 
     // do stuff 
    } 
    //... 
} 
+0

我還沒有添加'FUNC的tableView(UITableView的,didSelectRowAt:IndexPath)'。一旦我補充說,我將​​如何使用indexPath來確定哪個單元被點擊?謝謝。 – Miles

+0

'indexPath'具有屬性'row'和'section'。它看起來像你的表中只有一個部分(除非缺少部分設置),所以第一個單元格將在'indexPath.row == 0'處,第二個單元格是'indexPath.row == 1',等等。 – Samantha

+0

太好了,謝謝。使用override func tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath.row = 7)獲得錯誤{'with'row'不是'IndexPath'類型的成員。 'indexpath.row == 1'應該去哪裏?非常感謝你。 – Miles