- (void)viewDidLoad
{
[super viewDidLoad];
[NSThread detachNewThreadSelector:@selector(run2) toTarget:self withObject:Nil];
}
-(void)run2
{
for (int i=0; i<30; i++)
{
[NSThread sleepForTimeInterval:1];
//如果需要操作界面从子线程回到主线程,不然还是不能即使更新界面
[self performSelectorOnMainThread:@selector(updateUI:) withObject:@(i) waitUntilDone:NO];
}
}
-(void)updateUI:(NSNumber *)number
{
int i = [number intValue];
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(30, i*30, 20, 20)];
v.backgroundColor = [UIColor redColor];
[self.view addSubview:v];
}