重複をtableViewから削除しようとしています。テーブルビューでフェッチされるデータは、外部データベースから取得されます。フェッチされるデータのいくつかは数回繰り返されます。スイフト3:テーブルビューから重複したデータを削除できません
私が表示する必要があるデータは、プロファイル名と地域、つまりすべて表示、北、東、南、西です。今、3つの地域に現れるプロフィール(例えばジョージのコンクリートの場合)があります。たとえば、北、東、西です。デフォルトでは、ビューが読み込まれると、すべての地域のすべてのビジネスが表示されます。この見解では、私はいくつかのビジネスが繰り返されています。私たちのジョージのコンクリートのプロフィールはこのビューで3回繰り返され、一回だけ繰り返す必要があります。ノース/イースト/ウエストをクリックすると、ジョージのコンクリートもそこに一度だけ現れます。
ジョージのコンクリートは、3つの地域に3つの企業がありますが、他の地域をクリックすると1回だけ表示されるはずです。スクリーンショットを参照してください。
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<StorageSubCatagoriezTwo>()
var subCatagorizeDataTwoN = Array<StorageSubCatagoriezTwoNorth>()
var subCatagorizeDataTwoE = Array<StorageSubCatagoriezTwoEast>()
var subCatagorizeDataTwoW = Array<StorageSubCatagoriezTwoWest>()
var subCatagorizeDataTwoS = Array<StorageSubCatagoriezTwoSouth>()
var SubCatagoriez3rd = Array<StorageSubCatagoriez3rd>()
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.bussinessTableView.dequeueReusableCell(withIdentifier: "bussinessCell", for: indexPath) as! BussinessCell
let tableObjects:StorageSubCatagoriezTwo = subCatagorizeDataTwo[indexPath.row]
//let charCheck = (tableObjects.address).replacingOccurrences(of: " ", with: "")
if reg == "North"
{
cell.bussinessName.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.bussinessName.text = " "
let tableObjects:StorageSubCatagoriezTwoEast = subCatagorizeDataTwoE[indexPath.row]
cell.bussinessName.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.bussinessName.text = " "
let tableObjects:StorageSubCatagoriezTwoSouth = subCatagorizeDataTwoS[indexPath.row]
cell.bussinessName.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.bussinessName.text = " "
let tableObjects:StorageSubCatagoriezTwoWest = subCatagorizeDataTwoW[indexPath.row]
cell.bussinessName.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.bussinessName.text = tableObjects.nameString
let charCheck = (tableObjects.address).replacingOccurrences(of: " ", with: "")
cell.bussinessName.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.bussinessTableView.dequeueReusableCell(withIdentifier: "bussinessCell2")
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.bussinessTableView.dequeueReusableCell(withIdentifier: "bussinessCell3")
cell?.textLabel?.text = tableObjects.nameString
return cell!
}
}
func removeDuplicateはINTの配列を探していますが、文字列を渡しています。 – Douglas
[String]として使用しようとしましたが、「タイプ '[String]'の値をStorageSubCatagoriezTwoNorthに割り当てることができません。 –
StorageSubCatは何ですか...? – Douglas