您应该在主线程中对 UI 进行的所有修改,尝试使用performSelectorOnMainThread:withObject:waitUntilDone:
称呼
//...
for(int i=0;i<[testochar count];i++){
NSString *y=[testochar objectAtIndex:i];
[NSThread sleepForTimeInterval:0.1f];
NSDictionary *arg = [NSDictionary dictionaryWithObjectAndKeys:
self.txtview, @"textView",
y, @"string", nil ];
[self performSelectorOnMainThread:@selector(updateTextForTextView:) withObject:arg waitUntilDone:NO];
}
//.....
-(void)updateTextForTextView:(NSDictionary*)arg {
NSString *string = [arg objectForKey:@"string"];
UITextView *textView = [arg objectForKey:@"textView"];
self.txtview.text=[self.txtview.text stringByAppendingString:string];
}
(更新)
尝试
- (void)viewDidLoad {
[super viewDidLoad];
textView.text = @"";
[[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:nil repeats:YES] retain];
}
-(void) update {
static char text[] = "HELLO";
static int i =0;
if (text[i%6]==0) {
textView.text = [NSString stringWithFormat:@""];
} else {
textView.text = [NSString stringWithFormat:@"%@%c", textView.text, text[i%6] ];
}
i++;
}
它的工作方式如下:
http ://www.youtube.com/watch?v=tB2YKX4zpY4