テーブルビューに表示する製品アイテムのリストがあります。同時に、他のAPI呼び出しがあり、製品のアイテム名を渡して確認します。その商品アイテムが利用可能な場合、その特定のデータまたはアイテムセルのみが強調表示され、無効になります。
今私が必要としているのは、API呼び出しを行うとき、そしてその後、その特定のデータまたは製品名がそのAPIで利用可能である場合、強調表示して無効にするのではなく...テーブルビューにその特定のデータを表示しないでください。
どうやってするか:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! AllConnectionsTableViewCell
if let contact = filtered?[indexPath.row]{
cell.emailOutlet.text = AccountDataCache.sharedInstance.displayMaskAccnt(items: product.name)
cell.nameOutlet.text = product.name
if let _ = self.checkapicall(items: product.name){
// here if my product name is availble in api, then only the backgroudnd and it will be disabled
if let product = filtered?[indexPath.row]{
cell.namelabel.text = product.name
if let _ = self.checkapicall(items: product.vpa){
cell.cellOuterView.backgroundColor = UIColor.red
cell.isUserInteractionEnabled = false
}else{
cell.cellOuterView.backgroundColor = UIColor.white
cell.isUserInteractionEnabled = true
}
}
}
BGを変更する代わりに、Disable..iはそのテーブルビューセルにそのデータを表示しないようにする必要があります。その方法は?
ありがとう
説明したように、データが次のようになっている場合:
name1, name2,name3, name4
次に、に4つの行を表示しますtableView
。
name2
API呼び出しで利用可能な場合は、次のように表示します。
name1, name3, name4
したがって、更新を開始する前に、すべての名前を取得する必要がありますtableView
。これは、に表示する行数を設定する必要があるためですtableView
。
あなたはこのようなことをすることができます(今日あなたがどのようにあなたのデータをフェッチするかはわかりませんが、これはあなたが始めるための例です):
// check add edit to your product
var products = [Product(name: "name1", vpa: "1"), Product(name: "name2", vpa: "2"), Product(name: "name3", vpa: "3"), Product(name: "name4", vpa: "4")]
// set the produts count
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return products.count
}
// just set the name here, don´t make any checks
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "StartPageCell", for: indexPath)
cell.namelabel.text = product.name
return cell
}
// check the names here and then reload the tableView
func checkNames() {
for product in products {
if self.checkapicall(items: product.vpa){ {
if let index = products.index(where: { $0.vpa == vpa }) {
products.remove(at: index)
}
}
}
tableView.reloadData()
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加