2017-07-07 70 views
2

我創建了一個靜態TableView,我想添加或刪除披露指標,具體取決於我們是在諮詢我們自己的帳戶還是訪客帳戶。在Swift中靜態TableView中的特定單元格的披露指標

這是我想什麼:

let index = IndexPath(row: 4, section: 0) 

let cell = tableView.cellForRow(at: index) 
if currentUser { 
    cell.accessoryType = .none 
    //cell.backgroundColor = UIColor.red 
} 

我試圖把它放在viewDidLoad中的功能,但沒有奏效。我也試過cellForRowAt indexPath和相同的結果。

我該怎麼做?

+0

,是有其他的?這只是刪除配件...你在哪裏設置它? –

+1

如果單元格是靜態的,則使用IBOutlet來直接訪問單元格。 – vadian

回答

1

你與靜態細胞,使cellForRow不會得到所謂的工作工作。取而代之的是,只需將連接你的細胞並對其進行設置,這樣

enter image description here

+0

哦,是的.....就是這麼簡單....!非常感謝 ! – KevinB

3

只需檢查是否要在cellForRowAt indexPath方法中顯示披露指標。

if (wantsToShow){ // Your condition goes here 
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 
} 
else{ 
    cell.accessoryType = .none 
} 

就是這樣。

+0

問題是,它是一個靜態的TableView,我只想在單元[0,4]上做這個... – KevinB

0

請使用下面的代碼在cellForRowTableView代碼

它會爲你

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{ 
    if currentUser { 
    // Own Account 
     cell.accessoryType = .none 
     //cell.backgroundColor = UIColor.red 
    }else{ 
    //Guest Account 
    cell.accessoryType =.checkmark 
    } 
} 
相關問題