【发布时间】:2017-04-19 07:11:15
【问题描述】:
我正在使用下面提到的数组填充我的 tableView。如果用户搜索数组并找到项目,则应选择该单元格。
(
{
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 中比较该数组
标签: ios xcode uitableview swift3