我的tableview突然停止了滚动

时间:2015-08-18 05:27:52

标签: swift uitableview debugging scroll

我不太确定我做了什么,但不仅仅是我不能滚动。我无法选择表格中的任何项目。好像我的桌子被禁用了,但我确定它不是,至少我很确定。

包括我的代码,它有效,但可能有些东西我没有注意到。但同样,我没有做任何改变。

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 = ""
}
}

另外,我只是注意到一个小问题,自动换行不起作用。无论如何。所以是的,这是我的问题。它曾用于滚动,现在它没有。不知道为什么。

enter image description here

2 个答案:

答案 0 :(得分:1)

只需从属性检查器启用用户交互,如下图所示:

enter image description here

答案 1 :(得分:0)

对不起伙计们,我可以发誓用户互动已启用,但我猜不是。谢谢你指出来。叹。其中一天。