我有一個從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__);
}