I am trying to create a UILabel that will inform the user about what is happening while he is waiting. However, UILabel always delays its text update until the system goes into standby mode.
Process:
[infoLine performSelectorOnMainThread:@selector(setText:) withObject:@"Calculating..." waitUntilDone:YES]; [distanceManager calc]; // Parses a XML and does some calculations [infoLine performSelectorOnMainThread:@selector(setText:) withObject:@"Idle" waitUntilDone:YES];
Do not wait. Do you do this "immediately"?
, waitUntilDone. setText, setNeedsDisplay , NSTimer , , 1 , /. , , , , switch ( chunk, execute chunk, index chunk index, exit), . . , ( 15 200 ).
waitUntilDone , setText: , , .
waitUntilDone
setText:
, call -setNeedsDisplay , .
-setNeedsDisplay
Here's a useful feature that I added to the subclass UIViewController. It executes the selector in the next run loop. It works, but do you think I should make NSTimer *timeran instance variable, since this method will probably be called more than once.
UIViewController
NSTimer *timer
- (void)scheduleInNextRunloopSelector:(SEL)selector { NSDate *fireDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0.001]; // 1 ms NSTimer *timer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.0 target:self selector:selector userInfo:nil repeats:NO]; [fireDate release]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]; [timer release]; }
Use performSelector:(SEL) withObject:(id) afterDelay:(NSTimeInterval):
performSelector:(SEL) withObject:(id) afterDelay:(NSTimeInterval)
self.infoLine.text = @"Calculating..."; [self performSelector:@selector(likeABoss) withObject:nil afterDelay:0.001]; //... -(void) likeABoss { // hard work here self.infoLine.text = @"Idle"; }
Source: https://habr.com/ru/post/1762419/More articles:Is it possible to hide properties from a derived class? - c #UIImage at the end of the text UILabel - textC # hide from dervied classes some properties of a base class - inheritanceZero template with QObject - qtHow to assign the value of a control property from a global variable to the page code? - asp.netFast, thread safe Python ORM? - pythonIs there any tool for checking the consistency of fonts throughout the web application? - web-applicationsHow to break a SAX parser depending on the first known tag? - javaКак анализировать различные файлы XML, используя SAX на Android? - androidWhy emails don’t upload images directly - securityAll Articles