我正在使用下面提到的數組填充我的tableView。如果用戶搜索數組並找到了項目,那麼應該選擇該單元。如何使用函數來選擇UITableViewCell,而不用點擊它?
(
{
barcode = 8901058847857;
image = (
);
name = "Maggi Hot Heads";
productTotal = "60.00";
quantity = 3;
},
{
barcode = 8901491101837;
image = (
);
name = "Lays Classic Salted";
productTotal = "20.00";
quantity = 1;
}
)
我使用下述代碼來搜索條碼的數組,但我不知道如何進一步進行,如何在其他情況下,選擇tableViewCell。 有代碼寫入tableViewCell setSelected。
let namePredicate = NSPredicate(format: "barcode contains[c] %@",code)
let filteredArray = orderDetailsArray.filter { namePredicate.evaluate(with: $0) }
if filteredArray.isEmpty {
let alert = UIAlertController(title: "Alert", message: "Item not found in cart.", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: { action in
self.scan()
}))
self.present(alert, animated: true, completion: nil)
}else{
print("item found")
// Need to do selection here
}
您可以簡單地字符串數組,包含過濾條形碼和比較cellForRow –