Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift Post请求hud,收到响应后装载机未停止_Swift_Http Post_Loader_Hud - Fatal编程技术网

Swift Post请求hud,收到响应后装载机未停止

Swift Post请求hud,收到响应后装载机未停止,swift,http-post,loader,hud,Swift,Http Post,Loader,Hud,在Swift中,我使用post方法作为多部分图像上传,问题在于post方法当我得到响应时,我想停止加载程序,但它没有发生。我的意思是说加载程序没有停止,我使用的是BProgressHUD否则任何地方都可以正常工作。这是我的密码。获得图像后,我调用图像上载方法 func ImageUploadRequest_Profile() { BProgressHUD.showLoadingViewWithMessage("Loading...") let myUrl = NSUR

在Swift中,我使用post方法作为多部分图像上传,问题在于post方法当我得到响应时,我想停止加载程序,但它没有发生。我的意思是说加载程序没有停止,我使用的是
BProgressHUD
否则任何地方都可以正常工作。这是我的密码。获得图像后,我调用图像上载方法

  func ImageUploadRequest_Profile()
{


    BProgressHUD.showLoadingViewWithMessage("Loading...")


    let myUrl = NSURL(string: "\(WebServicesUrl.GlobalConstants.ImageUpload)");

    let request = NSMutableURLRequest(URL:myUrl!);
    request.HTTPMethod = "POST";

    let param = [
        "user_id"  : delegate.appd_userid,
        "at"    : "0",
        "profile_image"    : "Test"
    ]

    let boundary = generateBoundaryString()

    request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")


    compressImage()
    let imageData = UIImagePNGRepresentation(img_profilePhoto.image!)
    if(imageData==nil)  { return; }

    request.HTTPBody = createBodyWithParameters(param, filePathKey: "fileToUpload", imageDataKey: imageData!, boundary: boundary)





    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
        data, response, error in

        if error != nil {
            print("error=\(error)")
            return
        }

        // You can print out response object
        // print("******* response = \(response)")

        // Print out reponse body

        BProgressHUD.dismissHUD(0)


    }

    task.resume()

}
这是从库中获取图像的方法

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage


        img_profilePhoto.contentMode = .ScaleAspectFit
        img_profilePhoto.image = chosenImage

        ImageUploadRequest_Profile()

请帮帮我

打印时是否有错误?请尝试为dismissHUD方法提供静态值。对于例如bprogreshud.dismissHUD(2),然后测试它。dispatch_async(dispatch_get_main_queue()){bprogreshud.dismissHUD(0)}尝试此方法,希望对您有所帮助。是的,dispatch_async正在工作,但为什么会发生这种情况?它是否打印任何错误?尝试为dismissHUD方法提供静态值。例如BProgressHUD.dismissHUD(2),然后测试它。dispatch_async(dispatch_get_main_queue()){BProgressHUD.dismissHUD(0)}试试这个,希望能有所帮助。是的,dispatch_async正在工作,但为什么会发生这种情况