как поместить другие данные в ячейку, отфильтрованную по имени?
Я пропускаю эту проблему в течение нескольких дней.
Есть ли способ объединить разные данные в отфильтрованная ячейка?
var addressDetailCustomerName = [String]()
var addressDetailTargetHN = [String]()
var choList = [String]()
Хранит имя, имя которого было взято с сервера.
for i in 0..<self.addressDetailCustomerName.count {
self.choList.append(self.addressDetailCustomerName[i].initialConsonant()!)
}
Вот часть, которая приносит согласную
extension String {
func initialConsonant() -> String? {
guard let firstWord = self.first else { return nil }
guard let consonant =
String(firstWord).decomposedStringWithCompatibilityMapping.unicodeScalars.first else { return nil }
return UnicodeScalar(consonant).description
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return Array(Set(addressDetailCustomerName.map { $0.first!})).count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if self.searchBar.text?.isEmpty == true {
return String(Array(Set(choList.map { $0.first!})).sorted()[section])
}
return ""
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let charactor = Array(Set(addressDetailCustomerName.map { $0.first! })).sorted()[section]
if self.searchBar.text?.isEmpty == true {
return addressDetailCustomerName.filter { $0.first! == charactor }.count
}
return addressDetailCustomerName.filter { $0.first! == charactor }.filter { $0.contains(self.searchBar.text!) }.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "AddressItemTableViewCell", for: indexPath) as! AddressItemTableViewCell
let charactor = Array(Set(addressDetailCustomerName.map { $0.first! })).sorted()[indexPath.section]
cell.userNameLabel.text = addressDetailCustomerName.filter( {$0.first == charactor }) [indexPath.row]
return cell
}