Nested closures does not like argument list

后端 未结 2 1670
猫巷女王i
猫巷女王i 2020-12-17 19:17

A UIView needs to change a warning label depending on the completion handler of a custom control:

    voucherInputView.completionHandler = {[weak self] (succ         


        
2条回答
  •  悲&欢浪女
    2020-12-17 19:50

    Antonio's solution also applies with nested closures, like doing an AFNetworking request within UITableViewRowAction handler.

    override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    
        let cleanRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Do Stuff", handler: {[weak self](action: UITableViewRowAction!, indexPath: NSIndexPath!) in
    
            AFHTTPSessionManager(baseURL: NSURL(string: "http://baseurl")).PUT("/api/", parameters: nil, success: { (task: NSURLSessionDataTask!, response: AnyObject!) -> Void in
    
                    // Handle success
    
                    self?.endEditing()
                    return
                }, failure: { (task: NSURLSessionDataTask!, error: NSError!) -> Void in
    
                    // Handle error
    
                    self?.endEditing()
                    return
            })
            return
    
        })
    
        cleanRowAction.backgroundColor = UIColor.greenColor()
        return [cleanRowAction]
    }
    

提交回复
热议问题