Swift 3: Duplikate entfernen / in uitableviewcell als 1 gruppierenIOS

Programmierung für iOS
Guest
 Swift 3: Duplikate entfernen / in uitableviewcell als 1 gruppieren

Post by Guest »

Ich versuche, die doppelten Einträge, die aus der externen Datenbank abgerufen wurden, entweder zu entfernen oder sie als einen zu gruppieren. Ursprünglich hatte meine SQL-Abfrage eine Gruppenklausel. Als ich es als Gruppenklausel verwendete, funktionierte die Abfrage, aber nicht ordnungsgemäß. Anschließend habe ich die Gruppenklausel aus der Abfrage entfernt. Sie zeigt nun die doppelten Einträge an.
Ich habe vier Regionen: – Norden, Osten, Süden, Westen und ALLE
Standardmäßig werden alle Regionen angezeigt. Nun könnte es ein Profil geben, das in mehr als einer Region erscheint. Wenn es also standardmäßig alle Regionen lädt, sollte das Profil dort nur einmal angezeigt werden. Wenn wir jedoch auf die Regionen tippen, sollte das Profil auch dort angezeigt werden, wenn das Profil zu dieser Region gehört.
Im Moment wird alles zufällig angezeigt. Einige Profile, die in mehr als einer Region verfügbar sind, werden angezeigt, andere nicht. Einige Profile, die nur für eine Region bestimmt sind, werden in zwei Regionen angezeigt.
Ich weiß nicht, wie ich den Code oder die Screenshots weitergeben kann, stelle aber gerne weitere Details zur Verfügung der Anruf.
Danke
Mein Code:

Code: Select all

 func removeDuplicate (sourceArray: [String]) -> [String] {
var uniqueArray:[String] = []
for object in sourceArray {
if !uniqueArray.contains(object)
{
uniqueArray.append(object)
}
}
return uniqueArray
}

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

if indexPath.section == 0
{
let cell = self.businessTableView.dequeueReusableCell(withIdentifier: "businessCell", for: indexPath) as! BusinessCell

let tableObjects:StorageSubCatagoriezTwo = subCatagorizeDataTwo[indexPath.row]

let testing = removeDuplicate(sourceArray: [tableObjects.nameString])
print(testing.description)

//let charCheck = (tableObjects.address).replacingOccurrences(of: " ", with: "")

if reg == "North"
{
cell.businessName.text = " "
cell.addLabel.text = " "
cell.telLabel.text = " "
cell.emailLabel.text =  " "
cell.webLabel.text = " "
let tableObjects:StorageSubCatagoriezTwoNorth = subCatagorizeDataTwoN[indexPath.row]

if tableObjects.address.characters.isEmpty != true
{
cell.addLabel.text = tableObjects.address
}
else
{
//nothing
}
if tableObjects.telephone.characters.isEmpty != true
{
cell.telLabel.text = tableObjects.telephone
}
else
{

}
if tableObjects.email.characters.isEmpty != true
{
cell.emailLabel.text = tableObjects.email
}
else
{

}
if tableObjects.website.characters.isEmpty != true{
cell.webLabel.text = tableObjects.website
}
else{

}
}
else if reg == "East"
{
cell.businessName.text = " "
let tableObjects:StorageSubCatagoriezTwoEast = subCatagorizeDataTwoE[indexPath.row]
cell.businessName.text = tableObjects.nameString
if tableObjects.address.characters.isEmpty != true
{
cell.addLabel.text = tableObjects.address
}
else
{
//nothing
}
if tableObjects.telephone.characters.isEmpty != true
{
cell.telLabel.text = tableObjects.telephone
}
else
{

}
if tableObjects.email.characters.isEmpty != true
{
cell.emailLabel.text = tableObjects.email
}
else
{

}
if tableObjects.website.characters.isEmpty != true
{
cell.webLabel.text = tableObjects.website
}
else{

}
}
else if reg == "South"
{
cell.businessName.text = "  "
let tableObjects:StorageSubCatagoriezTwoSouth = subCatagorizeDataTwoS[indexPath.row]
cell.businessName.text = tableObjects.nameString
if tableObjects.address.characters.isEmpty != true
{
cell.addLabel.text = tableObjects.address
}
else
{
//nothing
}
if tableObjects.telephone.characters.isEmpty != true
{
cell.telLabel.text = tableObjects.telephone
}
else
{

}
if tableObjects.email.characters.isEmpty != true
{
cell.emailLabel.text = tableObjects.email
}
else
{

}
if tableObjects.website.characters.isEmpty != true{
cell.webLabel.text = tableObjects.website
}
else{

}
}
else if reg == "West"
{
cell.businessName.text = " "
let tableObjects:StorageSubCatagoriezTwoWest = subCatagorizeDataTwoW[indexPath.row]
cell.businessName.text = tableObjects.nameString
if tableObjects.address.characters.isEmpty != true
{
cell.addLabel.text = tableObjects.address
}
else
{
//nothing
}
if tableObjects.telephone.characters.isEmpty != true
{
cell.telLabel.text = tableObjects.telephone
}
else
{

}
if tableObjects.email.characters.isEmpty != true
{
cell.emailLabel.text = tableObjects.email
}
else
{

}
if tableObjects.website.characters.isEmpty != true{
cell.webLabel.text = tableObjects.website
}

}
else{
let tableObjects:StorageSubCatagoriezTwo = subCatagorizeDataTwo[indexPath.row]
cell.businessName.text = tableObjects.nameString

let charCheck = (tableObjects.address).replacingOccurrences(of: "  ", with: "")

cell.businessName.text = tableObjects.nameString
cell.addLabel.text = tableObjects.address
cell.telLabel.text = tableObjects.telephone
cell.emailLabel.text = tableObjects.email
cell.webLabel.text = tableObjects.website

}

return cell
}

else if indexPath.section == 1
{
let cell = self.businessTableView.dequeueReusableCell(withIdentifier: "businessCell2")
cell?.textLabel?.textAlignment = .center
switch regId
{
case 0:
if subCatagorizeDataTwo.count != forAll
{
cell?.textLabel?.text = "Load More Data"
cell?.textLabel?.textColor = Color.whiteColor
cell?.backgroundColor = UIColor.darkGray

}else{
cell?.textLabel?.text = "No More Data Found"
cell?.textLabel?.textColor = UIColor.darkGray
cell?.backgroundColor = UIColor.gray
cell?.selectionStyle = UITableViewCellSelectionStyle.none
}
case 1:
if subCatagorizeDataTwoN.count != forN
{
cell?.textLabel?.text = "Load More Data"
cell?.textLabel?.textColor = Color.whiteColor
cell?.backgroundColor = UIColor.darkGray

}else{
cell?.textLabel?.text = "No More Data Found"
cell?.textLabel?.textColor = UIColor.darkGray
cell?.backgroundColor = UIColor.gray
cell?.selectionStyle = UITableViewCellSelectionStyle.none
}
case 2:
if subCatagorizeDataTwoE.count != forE
{
cell?.textLabel?.text = "Load More Data"
cell?.textLabel?.textColor = Color.whiteColor
cell?.backgroundColor = UIColor.darkGray

}else{
cell?.textLabel?.text = "No More Data Found"
cell?.textLabel?.textColor = UIColor.darkGray
cell?.backgroundColor = UIColor.gray
cell?.selectionStyle = UITableViewCellSelectionStyle.none
}
case 3:
if subCatagorizeDataTwoS.count != forS
{
cell?.textLabel?.text = "Load More Data"
cell?.textLabel?.textColor = Color.whiteColor
cell?.backgroundColor = UIColor.darkGray

}else{
cell?.textLabel?.text = "No More Data Found"
cell?.textLabel?.textColor = UIColor.darkGray
cell?.backgroundColor = UIColor.gray
cell?.selectionStyle = UITableViewCellSelectionStyle.none
}
case 4:
if subCatagorizeDataTwoW.count != forW
{
cell?.textLabel?.text = "Load More Data"
cell?.textLabel?.textColor = Color.whiteColor
cell?.backgroundColor = UIColor.darkGray

}else{
cell?.textLabel?.text = "No More Data Found"
cell?.textLabel?.textColor = UIColor.darkGray
cell?.backgroundColor = UIColor.gray
cell?.selectionStyle = UITableViewCellSelectionStyle.none
}

default:break
}

return cell!
}
else
{
let tableObjects:StorageSubCatagoriez3rd = SubCatagoriez3rd[indexPath.row]
let cell = self.businessTableView.dequeueReusableCell(withIdentifier: "businessCell3")
cell?.textLabel?.text = tableObjects.nameString
return cell!

}
}
Image

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post