прежде чем спросить вас, я следовал 3 учебника, но безрезультатно.
У меня есть таблица с 20 разделами, и в каждой ячейке есть 2 надписи: 1 для заголовка и 1 для художника. Итак, у меня есть 20 массивов для заголовка в алфавитном порядке и 20 массивов для художника в алфавитном порядке.
Я хочу реализовать панель поиска между этими двумя массивами, основываясь только на массивах заголовков.
Возможно ли это?
вот мой код
import UIKit
class TableViewController: UITableViewController {
//Creo le sezioni
let sections = ["A","B","C","D","E","F","G","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","Z"]
let cantiTitles: [String] = ["A","B","C","D","E","F","G","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","Z"]
var categoriacliccata = 0
var rowCliccata = 0
@IBOutlet weak var searchBar: UISearchBar!
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
}
override func sectionIndexTitles(for tableView: UITableView) -> [String]? {
return cantiTitles
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("section: \(indexPath.section)")
categoriacliccata = indexPath.section
print("row: \(indexPath.row)")
rowCliccata = indexPath.row
performSegue(withIdentifier: "segue_testo", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "segue_testo") {
let secondVC: TextView_Controller = segue.destination as! TextView_Controller
secondVC.recivedCategoria = categoriacliccata
secondVC.recivedRow = rowCliccata
}
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section]
}
override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0:
return titoliA.count
case 1:
return titoliB.count
case 2:
return titoliC.count
case 3:
return titoliD.count
case 4:
return titoliE.count
case 5:
return titoliF.count
default:
return 0
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cellaCustom") as! Cella
switch indexPath.section {
case 0:
cell.lbl_titolo.text = titoliA[indexPath.row]
cell.lbl_artista.text = artistaA[indexPath.row]
break
case 1:
cell.lbl_titolo.text = titoliB[indexPath.row]
cell.lbl_artista.text = artistaB[indexPath.row]
break
case 2:
cell.lbl_titolo.text = titoliC[indexPath.row]
cell.lbl_artista.text = artistaC[indexPath.row]
break
case 3:
cell.lbl_titolo.text = titoliD[indexPath.row]
cell.lbl_artista.text = artistaD[indexPath.row]
break
case 4:
cell.lbl_titolo.text = titoliE[indexPath.row]
cell.lbl_artista.text = artistaE[indexPath.row]
break
case 5:
cell.lbl_titolo.text = titoliF[indexPath.row]
cell.lbl_artista.text = artistaF[indexPath.row]
break
default:
break
}
return cell
}
}