|
|
|
Xcode - อยากรู้ว่าถ้าจะเขียนแบบ AsyncTask เหมือน Android ต้องเขียนแบบไหนครับ?? |
|
|
|
|
|
|
|
AsyncTask มันเป็น Class ที่ถูกเขียนไว้บน Android ถ้า iOS น่าจะใช้ตัวนี้ครับ
Code (Objective-C)
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSURLRequest *theRequest =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.thaicreate.com/url/getGallery.php"]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
// Loading Show Alert View...
loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loading addSubview:progress];
[progress startAnimating];
[progress release];
[loading show];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
receivedData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if(receivedData)
{
// Hide Alert View
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[loading dismissWithClickedButtonIndex:0 animated:YES];
}
}
Ref
|
|
|
|
|
Date :
2015-02-07 19:51:11 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|