Swift 3: Doppelte Daten können nicht aus der Tabellenansicht entfernt werdenIOS

Programmierung für iOS
Guest
 Swift 3: Doppelte Daten können nicht aus der Tabellenansicht entfernt werden

Post by Guest »

Ich versuche, Duplikate aus der Tabellenansicht zu entfernen. Die in der Tabellenansicht abgerufenen Daten stammen aus einer externen Datenbank. Einige der abgerufenen Daten werden einige Male wiederholt.
Die Daten, die angezeigt werden müssen, sind der Profilname und die Region, d. h. Alle anzeigen, Norden, Osten, Süden, Westen. Jetzt kann es ein Profil geben (z. B. für George's Concreting), das in drei Regionen angezeigt werden kann. Zum Beispiel Norden, Osten und Westen. Wenn die Ansicht geladen wird, werden standardmäßig alle Unternehmen in allen Regionen angezeigt. Aus dieser Sicht habe ich einige Geschäfte, die sich wiederholen. Unser George's Concreting-Profil wird in dieser Ansicht dreimal wiederholt, wobei es nur einmal wiederholt werden sollte. Wenn ich auf Nord/Ost/West klicke, sollte George's Concreting dort auch nur einmal erscheinen.
Im Grunde sollte George's Concreting also nur einmal in „Alle anzeigen“ erscheinen, obwohl es 3 Unternehmen in 3 gibt Regionen und wenn wir auf die anderen Regionen klicken, sollte es auch einmal erscheinen. Bitte beachten Sie den Screenshot.
Bei Verwendung des folgenden Codes erhalte ich die Fehlermeldung „Bitte beachten Sie den Fehler“.
Code:

Code: Select all

class StorageSubCatagoriezTwo
{
var nameString:String
var idString:String
var address:String
var telephone:String
var email:String
var website:String

init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
}
}

class StorageSubCatagoriezTwoNorth
{
var nameString:String
var idString:String
var address:String
var telephone:String
var email:String
var website:String

init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
}
}

class StorageSubCatagoriezTwoEast
{
var nameString:String
var idString:String
var address:String
var telephone:String
var email:String
var website:String

init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
}
}

class StorageSubCatagoriezTwoWest
{
var nameString:String
var idString:String
var address:String
var telephone:String
var email:String
var website:String

init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.website = tempWebsite.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)    }
}

class StorageSubCatagoriezTwoSouth
{
var nameString:String
var idString:String
var address:String
var telephone:String
var email:String
var website:String

init(tempName:String,tempID:String,tempaddress:String,tempTelephone:String,tempEmail:String,tempWebsite:String)
{
self.nameString = tempName.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.idString  = tempID.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.address = tempaddress.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.telephone = tempTelephone.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.email = tempEmail.trimmingCharacters(in:  CharacterSet.whitespacesAndNewlines)
self.website = tempWebsite.trimmingCharacters(in:   CharacterSet.whitespacesAndNewlines)
}
}

___________________________________________________________

var subCatagorizeDataTwo = Array()
var subCatagorizeDataTwoN = Array()
var subCatagorizeDataTwoE = Array()
var subCatagorizeDataTwoW = Array()
var subCatagorizeDataTwoS = Array()
var SubCatagoriez3rd = Array()

func removeDuplicate (sourceArray: [Int]) -> [Int] {
var uniqueArray:[Int] = []
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 charCheck = (tableObjects.address).replacingOccurrences(of: " ", with: "")

if reg == "North"
{
cell.businessName.text = " "
cell.addLabel.text = " "
cell.telLabel.text = " "
cell.emailLabel.text =  " "
cell.webLabel.text = " "

var tableObjects:StorageSubCatagoriezTwoNorth = subCatagorizeDataTwoN[indexPath.row]
tableObjects = removeDuplicate(sourceArray: [tableObjects.nameString])
//**error** {Cannot convert value of type 'String' to expected element type 'Int'}

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!

}
}
Screenshot
Image

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post