Third-party wait indicator, MBPROGRESSHUD is the waiting indicator frame provided by the third party. The following is the wait indicator style provided by Mbprogresshud, which can be divided into two main types of wait indicators: unknown end time and known end time, in which Mbprogresshud can add labels and detailed labels for the wait indicator
Mbprogresshud's download address is Https://github.com/matej/MBProgressHUD and we will download the source The MBProgressHUD.h and MBPROGRESSHUD.M in the file are copied into their projects, and the Mbprogresshud-dependent frameworks are: Foundation.framework, Uikit.framework and Coregraphics.framework, we need to add these frameworks to the project.
We add the Mbprogresshud wait indicator for the application, modify the Startrequest method code for the main view controller masterviewcontroller.m as follows, and note the bold section:
-(void) startRequest
{
// Initialize MBProgressHUD
MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo: self.view animated: YES];
hud.mode = MBProgressHUDModeCustomView;
hud.labelText = @ ”Loading”;
NSString * strURL = [[NSString alloc]
initWithFormat: @ ”http: //iosbook3/mynotes/webservice.php”];
NSURL * url = [NSURL URLWithString: [strURL URLEncodedString]];
NSString * post;
if (action == ACTION_QUERY) {// Query processing
post = [NSString stringWithFormat: @ "email =% @ & type =% @ & action =% @",
@ "<Your iosbook1.com user email>", @ "JSON", @ "query"];
} else if (action == ACTION_REMOVE) {// delete processing
NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow];
NSMutableDictionary * dict = self.listData [indexPath.row];
post = [NSString stringWithFormat: @ "email =% @ & type =% @ & action =% @ & id =% @",
@ "<Your iosbook1.com user email>", @ "JSON", @ "remove", [dict objectForKey: @ "ID"]];
}
NSData * postData = [post dataUsingEncoding: NSUTF8StringEncoding];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL: url];
[request setHTTPMethod: @ "POST"];
[request setHTTPBody: postData];
NSURLConnection * connection = [[NSURLConnection alloc]
initWithRequest: request delegate: self];
if (connection) {
_datas = [NSMutableData new];
}
}
-(void) connection: (NSURLConnection *) connection didFailWithError: (NSError *) error {
NSLog (@ ”% @”, [error localizedDescription]);
[MBProgressHUD hideHUDForView: self.view animated: YES];
}
-(void) connectionDidFinishLoading: (NSURLConnection *) connection {
NSLog (@ "Request completed ...");
NSDictionary * dict = [NSJSONSerialization JSONObjectWithData: _datas
options: NSJSONReadingAllowFragments error: nil];
if (action == ACTION_QUERY) {// Query processing
[self reloadView: dict];
} else if (action == ACTION_REMOVE) {// delete processing
NSString * message = @ "Operation succeeded.";
NSNumber * resultCodeObj = [dict objectForKey: @ "ResultCode"];
if ([resultCodeObj integerValue] <0) {
message = [resultCodeObj errorMessage];
}
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "prompt message"
message: message
delegate: nil
cancelButtonTitle: @ ”OK”
otherButtonTitles: nil];
[alertView show];
//look up again
action = ACTION_QUERY;
[self startRequest];
}
[MBProgressHUD hideHUDForView: self.view animated: YES];
}
This article is from the "Dongsheng" blog, please be sure to keep this source http://2009315319.blog.51cto.com/701759/1174465