自定義對象的索引我有自定義對象的數組稱爲Service
和didSelectRow
我填充我選擇的對象的數組:查找陣列
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
let services:[Service] = self.menu[indexPath.section].services
self.selectedServices.append(services[indexPath.row])
}
}
的問題是,我無法弄清楚如何檢索從didDeselectRow:
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
cell.accessoryType = .None
let services = self.menu[indexPath.section].services
let service = services[indexPath.row]
//how can I found the index position of service inside selectedServices?
}
}
selectedServices [indexPath.row]怎麼樣 –
你有沒有試過self.selectedServices [indexPath.row]? – AgnosticDev
否請閱讀代碼 – Federic