因为苹果不允许在主线程以外的线程中对ui进行操作,所以需要将操作ui的部分放到主线程中执行,所以在子线程中,可以使用performSelectorOnMainThread去创建一个新的线程执行你的函数,支持传入参数。
NSArray *array=@[username,userpwd]; [self performSelectorOnMainThread: @selector(push:) withObject:array waitUntilDone:NO]; -(void)push:(NSArray *)array{//用户名,密码 UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main"bundle:[NSBundlemainBundle]]; UIViewController *myView = [story instantiateViewControllerWithIdentifier:@"TYLogin"]; [myView setValue:array[0] forKey:@"objUser"]; [myView setValue:array[1] forKey:@"objPwd"]; [self.navigationController pushViewController:myView animated:YES]; }