2015-09-28 101 views
0

我有一個從Xcode 6創建的項目。在根視圖控制器中,viewDidAppear經歷了這個奇怪的延遲。在下面的代碼中,如果從viewDidLoadviewWillAppear調用,更改的按鈕和背景顏色的創建將立即生效。但如果從viewDidAppear撥打電話,將會有延遲。viewDidAfter UI UI深不可測延遲

如果從viewDidLoadviewWillAppear創建按鈕,則該響應不是立即的。

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__); 
} 

回答

0

viewDidAppear:在視圖出現後調用,所以如果你正在做一些改變視圖覆蓋的東西,它會被察覺。如果您不想看到顏色變化,請在其他早期生命週期方法之一中設置顏色。

0

我發現Google的admob庫創建了這個問題。我正在使用版本6.4.x.請注意,正如我在我的問題所述,沒有任何加載AppDelegate或視圖控制器。在那個階段還沒有一個admob課程正在使用。

此問題只出現在iOS 9中。