我不太确定我做了什么,但不仅仅是我不能滚动。我无法选择表格中的任何项目。好像我的桌子被禁用了,但我确定它不是,至少我很确定。
包括我的代码,它有效,但可能有些东西我没有注意到。但同样,我没有做任何改变。
import UIKit
class SearchViewController: UIViewController, UITextViewDelegate, CLLocationManagerDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource
{
@IBOutlet weak var myTable: UITableView!
@IBOutlet weak var searchBar: UISearchBar!
var searchResults = [String]()
@IBAction func cancelPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true , completion: nil)
self.view.endEditing(true)
}
override func viewDidLoad() {
searchBar.tintColor = UIColor(red: 18.0/255, green: 163.0/255, blue: 255.0/255, alpha: 1)
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return searchResults.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let myCell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) as! UITableViewCell
myCell.textLabel?.text = searchResults[indexPath.row]
myCell.textLabel?.font = UIFont(name: "Lato", size: 18)
myCell.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
myCell.textLabel?.numberOfLines = 0
return myCell
}
func searchBarSearchButtonClicked(searchBar: UISearchBar)
{
searchBar.resignFirstResponder()
var textSearchQuery = PFQuery(className: "Go")
textSearchQuery.whereKey("text", containsString: searchBar.text)
var query = PFQuery.orQueryWithSubqueries([textSearchQuery])
query.findObjectsInBackgroundWithBlock
{
(results: [AnyObject]?, error: NSError?) -> Void in
if error != nil
{
//var myAlert = UIAlertController(title: "Alert", message: error?.localizedDescription, preferredStyle: UIAlertControllerStyle.self)
//let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
//myAlert.addAction(okAction)
//self.presentViewController(myAlert, animated: true, completion: nil)
return
}
if let objects = results as? [PFObject]
{
self.searchResults.removeAll(keepCapacity: false)
for object in objects
{
let searchText = object.objectForKey("text") as! String
self.searchResults.append(searchText)
}
dispatch_async(dispatch_get_main_queue())
{
self.myTable.reloadData()
self.searchBar.resignFirstResponder()
}
}
}
}
func searchBarCancelButtonClicked(searchBar: UISearchBar)
{
searchBar.resignFirstResponder()
searchBar.text = ""
}
}
另外,我只是注意到一个小问题,自动换行不起作用。无论如何。所以是的,这是我的问题。它曾用于滚动,现在它没有。不知道为什么。