【发布时间】:2015-08-07 14:07:12
【问题描述】:
我已经有一些在 tableview 上显示的项目。当我使用搜索栏进行搜索时,相同的表格视图会更新为新项目。(我今天的项目)。
但是如果我删除了我在搜索栏上写的内容,我需要返回它们之前的项目。 我怎样才能做到这一点 ?
import UIKit
import Alamofire
class MovieViewController: UIViewController, AsyncUpdateProtocol,UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var myTable: UITableView!
@IBOutlet weak var searchBar: UISearchBar!
var myArray: Array<Movie>!
var movieData: MovieData!
override func viewDidLoad() {
super.viewDidLoad()
searchBar.delegate = self
self.myTable.dataSource = self
self.movieData = MovieData(controllerUpdate: self)
self.myArray = self.movieData.data
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.movieData.data.count;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: AnyObject = self.myTable.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
cell.textLabel!!.text = self.movieData.data[indexPath.row].title
cell.textLabel!!.adjustsFontSizeToFitWidth = true
var url: NSURL
if((self.movieData.data[indexPath.row].poster ) != nil){
url = NSURL(string: "http://image.tmdb.org/t/p/w500\(self.movieData.data[indexPath.row].poster)") as NSURL!
}else{
url = NSURL(string: "http://developer-agent.com/wp-content/uploads/2015/05/images_no_image_jpg3.jpg") as NSURL!
}
var data = NSData(contentsOfURL: url) as NSData!
var imagem = UIImage(data: data!)
cell.imageView!!.image = imagem
return cell as! UITableViewCell
}
func searchBarSearchButtonClicked(searchBar: UISearchBar){
pesquisa(searchBar.text)
searchBar.resignFirstResponder()
}
func pesquisa(nome: String){
self.movieData.data.removeAll()
self.movieData.request(nome)
}
【问题讨论】:
-
这里的每个人都想帮助你,但除非你把你的代码放到你的问题中,否则很难做到。
-
我不知道会不会有很大帮助,但是就在这里。