我的视图中有一个parseTableViewController,parseTableViewCell和UISearchBar插座。数据按预期进行,但是当我搜索时没有任何事情发生,有时它会崩溃应用程序。这是我的代码,没有错误。我想我在这里错过了一点......谢谢
import UIKit
import ParseUI
import Parse
class profilTableViewController: PFQueryTableViewController, UISearchBarDelegate{
let backgroundImage = UIImage(named: "A.png")
var arka: UIImageView!
@IBOutlet weak var searchBar: UISearchBar!
override func viewDidLoad() {
super.viewDidLoad()
arka = UIImageView(frame: view.bounds)
arka.contentMode = .ScaleToFill
arka.clipsToBounds = true
arka.image = backgroundImage
arka.center = view.center
view.addSubview(arka)
self.view.sendSubviewToBack(arka)
tableView.backgroundView = arka
self.addEffect()
}
override init(style: UITableViewStyle, className: String!) {
super.init(style: style, className: className)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.parseClassName = "ProfilListesi"
self.textKey = "profileName"
self.pullToRefreshEnabled = true
self.paginationEnabled = false
}
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "ProfilListesi")
if searchBar.text != "" {
query.whereKey("profileName", containsString: searchBar.text!.lowercaseString)
}
query.cachePolicy = .CacheThenNetwork
query.orderByAscending("profileName")
query.limit = 1000
return query
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
searchBar.resignFirstResponder()
self.loadObjects()
}
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
searchBar.resignFirstResponder()
self.loadObjects()
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
searchBar.text = ""
searchBar.resignFirstResponder()
self.loadObjects()
}
override func viewDidAppear(animated: Bool) {
tableView.reloadData()
searchBar.delegate = self
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> profilTableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("profilSegue") as! profilTableViewCell!
if cell == nil {
cell = profilTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "profilSegue")
}
if let profil = object?["profileName"] as? String {
cell?.profilLabel?.text = profil
}
if let sistem = object?["profileType"] as? String {
cell?.sistemLabel?.text = sistem
}
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "detaySegue" {
var detailScene = segue.destinationViewController as! profilDetayViewController
if let indexPath = self.tableView.indexPathForSelectedRow {
let row = Int(indexPath.row)
detailScene.currentObject = (objects?[row] as! PFObject)
}
}
}
func addEffect()
{
let effect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let effectView = UIVisualEffectView(effect: effect)
effectView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
arka.addSubview(effectView)
arka.layer.cornerRadius = 0
arka.layer.masksToBounds = true;
}
}