In my previous blog, "iOS development-using Mbprogresshud to add user experience," The main realization of the use of others have been encapsulated Mbprogresshud to load the hint, can be said to be quite convenient. Today we use the native Mbprogresshud third-party repository on GitHub to load hints that are a little more troublesome than others have already encapsulated. The code has been uploaded to: Https://github.com/chenyufeng1991/UseMBProgressHUD. The implementation steps are as follows:
(1) Also use the network request number attribution place to implement. (See note)
-(Ibaction) sourcebuttonpressed: (ID) Sender {//Declaration object; Mbprogresshud *hud = [Mbprogresshud ShowHUDAddedTo:self.view anima Ted:true]; The text to be displayed; Hud.labeltext = @ "Loading"; Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanager manager]; Manager.responseserializer = [Afhttpresponseserializer serializer]; This is changed to post, you can make a POST request,//Put the parameters to be passed directly into the URL, rather than in the dictionary; [Manager get:@ "http://webservice.webxml.com.cn/WebServices/ Mobilecodews.asmx/getmobilecodeinfo?mobilecode=18888888888&userid= "Parameters:nil success:^ (AFHTTPRequestOp Eration *operation,id responseobject) {nsstring *string = [[NSString alloc] Initwithdata:res Ponseobject encoding:nsutf8stringencoding]; NSLog (@ "Success:%@", string); Successful loading, first remove the original HUD; hud.removefromsuperviewonhide = true; [HUD Hide:true afterdelay:0]; Then a successful prompt is displayed; Mbprogresshud *successhud = [Mbprogresshud showHUDAddedTo:self.view animated:true];Successhud.labeltext = @ "Load succeeded"; Successhud.mode = mbprogresshudmodecustomview;//custom view;//You can set the corresponding picture; successhud.customview = [[Uiimageview Alloc] Initwithimage:[uiimage imagenamed:@ "Success"]; Successhud.removefromsuperviewonhide = true; [Successhud hide:true afterdelay:1]; } failure:^ (Afhttprequestoperation *operation,nserror *error) {NSLog (@ "failed:%@", error); Hud.removefromsuperviewonhide = true; [HUD Hide:true afterdelay:0]; Display of failed prompts; Mbprogresshud *failhud = [Mbprogresshud showHUDAddedTo:self.view animated:true]; Failhud.labeltext = @ "failed to load"; Failhud.mode = Mbprogresshudmodecustomview; Failhud.customview = [[Uiimageview alloc] initwithimage:[uiimage imagenamed:@ "error"]; Failhud.removefromsuperviewonhide = true; [Failhud hide:true afterdelay:1]; }]; }
(2) The display effect is as follows:
"Loading"
。
"Load succeeded"
。
"Load Failed"
。
As you can see, using the default HUD requires a lot of code, and if you're more interested, you could encapsulate it yourself. This can greatly simplify the amount of code.
GitHub Home:https://github.com/chenyufeng1991 . Welcome everyone to visit!
iOS development-using Mbprogresshud to increase user experience (ii)