2017-04-20 40 views
1

我在刪除tableview部分的重複時遇到了問題。我正在使用2節,因此我想刪除第1節中已有的第2節中的項目重複項,請引導我進行介紹。我正在使用兩個數組,這些數組來自使用WCF Web服務的sql服務器。這是我cellforrowAt代碼如何從UITableView部分刪除重複項Swift 3

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

var cell : UITableViewCell! 


if tableView == self.diseasetableview 
{ 
let cell1 = tableView.dequeueReusableCell(withIdentifier: "diseasenamecell", for: indexPath) as! FoodTableViewCell 

cell1.selecteddiseasename.text = selectedDiseaseName[indexPath.row] 
    cell = cell1 

} 
if tableView == self.foodtableview 
{ 
    if indexPath.section == 0 
    { 
     print(indexPath.section) 
    let cell2 = tableView.dequeueReusableCell(withIdentifier: "foodnamecell", for: indexPath) as! FoodnameTableCell 

    cell2.foodnamelbl.text = food[indexPath.row] 
    cell = cell2 
    } 
    if indexPath.section == 1 
    { 

     print(indexPath.section) 
     print(notRecomended[indexPath.row]) 

     let cell3 = tableView.dequeueReusableCell(withIdentifier: "foodnamecell", for: indexPath) as! FoodnameTableCell 

      cell3.foodnamelbl.text = notRecomended[indexPath.row] 
      cell = cell3 


    } 

} 
return cell 

}

+0

檢查和之前移除重複在控制器** **重新加載表視圖。或者從服務器接收數據後立即過濾重複項。 – vadian

+0

感謝的人...... –

回答

0

必須使用下面碼的filered陣列和用於該部分使用過濾陣列

 let notRecomended = ["food1", "food3", "food4", "food2", "food6","food2"] 
    let food = ["food1", "food2"] 
    let filteredResult = notRecomended.filter { !food.contains($0) }) } 
+0

非常感謝..... –

0

檢查你的第二個數組中的重複和刪除重複項。

secondArray = secondArray.filter {firstArray.contains($0) == false} 
+0

謝謝我現在工作..... –

+0

wc。如果它幫助你:)。 – ankit

+0

如果你不介意爲我的問題投票,我很願意,但我的名譽是不夠的 –