Swift 3: удаление дубликатов/группировка их как 1 в uitableviewcellIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 Swift 3: удаление дубликатов/группировка их как 1 в uitableviewcell

Сообщение Anonymous »

Я пытаюсь либо удалить повторяющиеся записи, полученные из внешней базы данных, либо сгруппировать их как одну. Изначально мой SQL-запрос содержал групповое предложение. Когда я использовал его как групповое предложение, запрос работал, но некорректно. Затем я удалил предложение группы из запроса, теперь в нем отображаются повторяющиеся записи.
У меня есть четыре региона: - Север, Восток, Юг, Запад и ВСЕ
По умолчанию отображается весь регион. Теперь профиль может появляться более чем в одном регионе. Поэтому, когда он загружается по умолчанию — все регионы, профиль должен отображаться там только один раз, но когда мы переходим к регионам, профиль также должен отображаться там, если профиль принадлежит этому региону.
В этот момент все отображается случайно. Некоторые профили, доступные более чем в одном регионе, появляются, а некоторые нет. Некоторые профили, предназначенные для использования только в одном регионе, появляются в двух регионах.
Я не знаю, как поделиться кодом или скриншотами, но буду рад предоставить более подробную информацию для просмотра. звонок.
Спасибо
Мой код:

Код: Выделить всё

 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!

}
}
Изображение


Подробнее здесь: https://stackoverflow.com/questions/454 ... leviewcell
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «IOS»