2017-03-07 109 views
0

我使用SWRevealViewController創建了滑出菜單(UITableView),菜單中包含阿拉伯語字符串,但如果按某些字符串,菜單應重新加載新數據;UITableView不適用於阿拉伯語語言單元格

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MenuTableViewCell 
    if cell.label.text == "الرئيسية" { 
     menuTitles = menuTitlesName 
     self.tableView.reloadData() 
    } 
} 

它不會做任何事情,我不能跟indexPath工作,因爲會的tableView重新裝入一個新的數據,所以有什麼建議?!

+1

,在您正在檢查這個條件?請添加更多代碼,以便我們可以進一步幫助您。 – Pankaj

+0

@王子退房,編輯! –

+0

'dequeueReusableCell'不屬於'didSelectRowAt'委託方法,您應該使用['cellForRow(at:)'](https://developer.apple.com/reference/uikit/uitableview/1614983-cellforrow))來獲取'現有'細胞。 – user28434

回答

2

你可以從選擇的cellForRowAtIndexPath細胞實例,然後檢查你的標籤文本,並刷新數據

let currentCell = tableView.cellForRow(at: indexPath) as! MenuTableViewCell 
if cell.label.text == "الرئيسية" { 
    menuTitles = menuTitlesName 
    self.tableView.reloadData() 
} 
+0

問題有'swift3 '標籤,但你的代碼是'swift2'。 – user28434

+1

@ user28434更新了我的代碼。 – Pankaj