我有一个从Xcode 6创建的项目。在根视图控制器中,viewDidAppear
经历了这个奇怪的延迟。在下面的代码中,如果从viewDidLoad
或viewWillAppear
调用,更改的按钮和背景颜色的创建将立即生效。但如果从viewDidAppear
拨打电话,将会有延迟。viewDidAfter UI UI深不可测延迟
如果从viewDidLoad
或viewWillAppear
创建按钮,则该响应不是立即的。
viewDidAppear
中的加法运算是立即生效的。
当前和主线程1.
在AppDelegate
,没有什么didFinishLaunchingWithOptions
。
在视图控制器的init中没有任何加载。
有什么建议吗?
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
[self createButton];
NSLog(@"%s currentthread:%@ mainthread:%@", __PRETTY_FUNCTION__,[NSThread currentThread], [NSThread mainThread]);
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.backgroundColor = [UIColor cyanColor];
// [self createButton];
NSLog(@"%s currentthread:%@ mainthread:%@", __PRETTY_FUNCTION__,[NSThread currentThread], [NSThread mainThread]);
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"%s currentthread:%@ mainthread:%@", __PRETTY_FUNCTION__,[NSThread currentThread], [NSThread mainThread]);
self.view.backgroundColor = [UIColor blueColor];
int i = 2;
int j = 4;
int m = i + j;
NSLog(@"%s i:%u j:%u m: %u", __PRETTY_FUNCTION__, i,j, m);
// [self createButton];
}
-(void)createButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"button" forState:UIControlStateNormal];
[button addTarget: self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(50, 50, 100, 40);
[self.view addSubview:button];
}
-(void)buttonPressed:(id)sender
{
NSLog(@"%s", __PRETTY_FUNCTION__);
}