テーブルビューの検索バーが必要ですが、初心者であり、私は頭を悩ましています。セクションを含むTableViewで検索バーを作成するにはどうすればよいですか?
私のテーブルビューには、いくつかのセクションがあります。各セクションには、名前と日付を含む項目が入力されます。私はユーザーがその名前を使って研究をすることができるようにしたい。
もう1つ:もっと簡単に整理するために、私は列挙型を作成し、それをセクションの名前に使用したいと考えています。
私が達したどこまで表示する例作った:
class Cinema: UITableViewController {
// MARK: - Properties
var movie:[(type: Genre, data:[Movies])] = []
//MARK: - Super Methods
override func viewDidLoad() {
super.viewDidLoad()
movie = [
(Genre.Action, [
Movies (name: "Matrix", year: "1999", description: "A computer hacker learns from mysterious rebels about the true nature of his reality and his role in the war against its controllers."),
Movies (name: "Gladiator", year: "2000", description: "When a Roman general is betrayed and his family murdered by an emperor's corrupt son, he comes to Rome as a gladiator to seek revenge."),
Movies (name: "Saving Private Ryan", year: "1998", description: "Following the Normandy Landings, a group of U.S. soldiers go behind enemy lines to retrieve a paratrooper whose brothers have been killed in action.")
]),
(Genre.Drama, [
Movies (name: "Good Will Hunting", year: "1997", description: "Will Hunting, a janitor at M.I.T., has a gift for mathematics, but needs help from a psychologist to find direction in his life."),
Movies (name: "Schindler's List", year: "1993", description: "In Poland during World War II, Oskar Schindler gradually becomes concerned for his Jewish workforce after witnessing their persecution by the Nazis.")
]),
(Genre.Comedy, [
Movies (name: "Monty Python and the Holy Grail", year: "1975", description: "King Arthur and his knights embark on a low-budget search for the Grail, encountering many, very silly obstacles."),
Movies (name: "Hangover", year: "2009", description: "Three buddies wake up from a bachelor party in Las Vegas, with no memory of the previous night and the bachelor missing. They make their way around the city in order to find their friend before his wedding.")
])
]
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return movie.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return movie[section].data.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! ADTableViewCell
cell.title.text = movie[indexPath.section].data[indexPath.row].name
cell.year.text = movie[indexPath.section].data[indexPath.row].year
return cell
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Action"
} else if section == 1 {
return "Drama"
} else {
return "Comedy"
}
}
}
PS:ユーザーは、彼が選択した行をクリックすると、彼がいることのUIViewControllerに送信されますが名前、年、説明が表示されます。この例では、ここでprepareForSegueを作成しませんでした。
ありがとうございます。