私はsearchControllerの値を取り込む配列を持っていなければなりません。searchControllerの結果として異なる配列から2つの値をロードするには?
let textLabel = ["Uni", "Uni", "Faber-Castell", "Faber-Castell","Faber-Castell", "Pilot", "Pilot"]
let detailTextLabel = ["Pen", "Pencil", "Crayon", "Mechanical Pencil", "Contour Pencil", "Eraser", "Sharpener"]
これら二つの配列対UITableViewController.
同様(ユニ、PEN)、(ユニ、鉛筆)、(ファーバーカステル、クレヨン)のデータをリロードしながら...ペアで
、最初のものですセルのタイトル、2番目はサブタイトルです。私はiOSCreator's tutorialに続いた。
私の問題は、テキストを検索するときにタイトルセクションのみが更新され、サブタイトルは予想通りに更新されないということです。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
// 3
if (self.resultSearchController.active) {
// it only updates textLabel. But when I add detailTextLabel
// subtitles comes wrong because first array contains one element
// more than twice.
cell.textLabel?.text = filteredTableData[indexPath.row]
return cell
} else {
cell.textLabel?.text = tableData[indexPath.row]
return cell
}
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
filteredTableData.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text)
let array = (tableData as NSArray).filteredArrayUsingPredicate(searchPredicate)
filteredTableData = array as! [String]
self.tableView.reloadData()
}
は、AppleのUISearchControllerのソースコードをチェックしてください区切ら。 –