0
删除重复数据。在tableview上获取的数据来自外部数据库。一些获取的数据会重复几次。斯威夫特3:我想请从重复的tableView不能从的tableView
,我需要显示的数据是配置文件名称和区域即全部显示,北,东,南,西。现在,可以有一个可以出现在3个地区的配置文件(例如,George's Concreting)。例如北部,东部和西部。默认情况下,视图加载时会显示所有地区的所有业务。在这个观点上,我有一些重复的企业。我们的乔治的Concreting配置文件在这个视图中重复3次,只应重复一次。当我点击North/East/West时,George的Concreting应该只出现一次。
所以基本上,乔治的混凝土浇筑应仅在展会虽然它有3家企业在3个区域,当我们点击其他地区,也应该出现一次出现一次全部。请参阅截图。
使用下面的代码我得到的和错误上线,请参考**** ****错误
编码:
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