I am trying to dynamically update the text in a UITextField while in a loop and the text does not show up in real time. When the loop is complete it will display the final value. How do I get the text to display each time it is updated in the loop? I have found many threads on updating in a tableview but this text field is just on the main app. Here is a simple app with a text field and a button.
in ViewController.h #import
@interface ViewController : UIViewController<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *myText;
@property (weak, nonatomic) IBOutlet UIButton *myButton;
- (IBAction)pressMe:(UIButton *)sender;
@end
in ViewController.m #import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize myButton,myText;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
myText.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)pressMe:(UIButton *)sender {
for (int i=0;i<10;i++){
NSString *m = [[NSString alloc] initWithFormat:@"%d",i];
NSLog(@"%@",m);
[myText setText:m];
[NSThread sleepForTimeInterval:.05];
}
}
@end
The texfield delegate is connected to the view controller. This is a simple app to illustrate what I am trying to do. My actual app is trying to display lat lon from the gps to the screen with continual updates. Any help is appreciated.
0 comments:
Post a Comment