UIRefreshControl:发送到实例的无法识别的选择器 - absoluteURL

时间:2015-02-28 00:22:29

标签: ios swift selector nsurl uirefreshcontrol

在开始之前,我已经完成了与此问题相关的每一个问题。没有帮助。

我想刷新从tableView获取的tableView的json内容。

每个类别的网址来自另一个列有其中所有类别的文件。

获取内容的代码是

func animalSelected(animal: Animal) {

var request: NSURLRequest = NSURLRequest(URL: animal.url!)

   self.refresh(animal.url!)
    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithURL(animal.url!, completionHandler: {data, response, error -> Void in
        //   println("Task completed")
        if(error != nil) {
            // If there is an error in the web request, print it to the console
            println(error.localizedDescription)
        }
        var err: NSError?

        var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
        if(err != nil) {
            // If there is an error parsing JSON, print it to the console
            println("JSON Error \(err!.localizedDescription)")
        }
        let results: NSArray = jsonResult["posts"] as NSArray
        self.didReceiveResults(jsonResult)

    })
    task.resume()

    delegate?.collapseSidePanels?()

}

func didReceiveResults(results: NSDictionary) {
    var resultsArr: NSArray = results["posts"] as NSArray
    dispatch_async(dispatch_get_main_queue(), {
        self.tableData = resultsArr
        self.tableView.reloadData()
    })
}

我的ViewDidLoad方法和refresh方法如下所示

override func viewDidLoad() {
    super.viewDidLoad()
            refresher = UIRefreshControl()
            refresher.attributedTitle = NSAttributedString(string: "Pull to Refresh")
            refresher!.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)

            self.tableView.addSubview(refresher)
}

func refresh(categoryUrl : NSURL) {

    var request: NSURLRequest = NSURLRequest(URL: categoryUrl)

   let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithURL(categoryUrl, completionHandler: {data, response, error -> Void in
        if(error != nil) {
            // If there is an error in the web request, print it to the console
            println(error.localizedDescription)
        }
        var err: NSError?

        var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
        if(err != nil) {
            // If there is an error parsing JSON, print it to the console
            println("JSON Error \(err!.localizedDescription)")
        }
        let results: NSArray = jsonResult["posts"] as NSArray
        self.didReceiveResults(jsonResult)

    })
    task.resume()
    self.refresher.endRefreshing()

           }

我需要刷新已选择的相同URL的内容,即刷新相同的类别。

我收到此错误:[UIRefreshControl absoluteURL]: unrecognized selector sent to instance 0x7fa0b3d73750

我认为这与absoluteURL有关。不知道它是什么..

plsss plssssss plssss help

1 个答案:

答案 0 :(得分:0)

您试图获得absoluteURL UIRefreshControl您认为实际上是NSURL

确切地说,refresh(categoryUrl: NSURL)中的发件人是UIRefreshControl而不是NSURL