Note that there are some explanatory texts on larger screens.

plurals
  1. POAbout how to use NSThread
    primarykey
    data
    text
    <p>I'm an iPhone developer. I studied about how to use NSThread. So I created source code. But, I'm not sure about my source code whether good or bad.</p> <pre><code> -(void)check_threadEnd { if ([_thread isFinished]) { threadCount++; if (threadCount == 4) { [self performSelector:@selector(removeActivityView) withObject:nil afterDelay:0.0]; [self.tableView reloadData]; } } } </code></pre> <p>Sometimes, threadCount doesn't become 4. So, ActiveView is worked continual without stopping. Turn the timer after a period of time, remove ActiveView? I'll give you some advice please.</p> <pre><code>-(IBAction)click_ServerSync:(id)sender { if ([util checkNetwork]) { threadCount = 0 ; [self displayActivityView]; NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; [queue setMaxConcurrentOperationCount:4]; _thread = [[NSThread alloc] initWithTarget:self selector:@selector(_th) object:nil]; [_thread start]; } } -(void)_th { [self performSelectorOnMainThread:@selector(LoadXml:) withObject:@"XML1" waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(LoadXml:) withObject:@"XML2" waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(LoadXml:) withObject:@"XML3" waitUntilDone:NO]; [self performSelectorOnMainThread:@selector(LoadXml:) withObject:@"XML4" waitUntilDone:NO]; } -(void)LoadXml:(NSString*)P_VAL { NSString *smsURL = [NSString stringWithFormat:@"%@%@.asp", XML_URL, P_VAL]; NSString *sendAuthInfo = [NSString stringWithFormat:@"A=%@&amp;B=%d&amp;C=%@&amp;D=%@" , A, B, C, D ]; NSString *val = [sendAuthInfo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:smsURL]]autorelease]; [request setURL:[NSURL URLWithString:smsURL]]; [request setHTTPMethod:@"POST"]; [request setHTTPBody: [val dataUsingEncoding: NSUTF8StringEncoding]]; [self startAsyncLoad:request tag:P_VAL]; } - (void)startAsyncLoad:(NSMutableURLRequest*)request tag:(NSString*)tag { CustomURLConnection *connection = [[CustomURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES tag:tag]; if (connection) { [receivedData setObject:[[NSMutableData data] retain] forKey:connection.tag]; } } - (NSMutableData*)dataForConnection:(CustomURLConnection*)connection { NSMutableData *data = [receivedData objectForKey:connection.tag]; return data; } -(void)check_threadEnd { if ([_thread isFinished]) { threadCount++; if (threadCount == 4) { [self performSelector:@selector(removeActivityView) withObject:nil afterDelay:0.0]; [self.tableView reloadData]; } } } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSMutableData *dataForConnection = [self dataForConnection:(CustomURLConnection*)connection]; [dataForConnection setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSMutableData *dataForConnection = [self dataForConnection:(CustomURLConnection*)connection]; [dataForConnection appendData:data]; } -(void)connectionDidFinishLoading:(NSURLConnection*)connection { NSLog(@" connection connectionDidFinishLoading : %d", [connection retainCount]); NSMutableData *dataForConnection = [self dataForConnection:(CustomURLConnection*)connection]; [connection release]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; NSXMLParser *xmlParser = [[[NSXMLParser alloc] initWithData:dataForConnection] autorelease]; XMLParser *parser = [[XMLParser alloc] initXMLParser]; [xmlParser setDelegate:(id)parser]; parser.viewDelegate = (id)self; [xmlParser parse]; // xml parser } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload