2015-07-20 76 views
0

我正在創建新的UIViewController,但在顯示它之前等待幾秒鐘。 事情是我想viewDidLoad被調用之前,我實際上顯示現在的對象。我怎樣才能讓viewDidLoad運行?原因viewDidLoad運行

目前我在做這樣的事情:

UIView *tempView = newObject.view; 

但我真的不喜歡這樣的解決方案。

回答

0

看起來就像只是打電話[newObject view];訣竅!

0

如果存在想要運行的代碼,並希望在實例化視圖時調用該代碼,那麼只需將其放入init方法即可。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName: nibNameOrNil 
          bundle: nibBundleOrNil]; 
    if (self) 
    { 
     // Custom stuff 
    } 
    return self; 
} 

是否有另一個原因,你爲什麼要調用viewDidLoad

+0

我在那裏運行的一些代碼涉及視圖對象 – YogevSitton

0
- (void) viewDidLoad { 
     [super viewDidLoad]; 

     self.view.alpha = 0; //When alpha = 0, it is also hidden 
     [UIView animateWithDuration:2.0f animations:^{ 
      // Nothing to animate here 
     } completion:^(BOOL finished) { 
      // On animation completion show the content of the view, also animated. 
      [UIView animateWithDuration:0.5f animations:^{ 
       self.view.alpha = 1; 
      }]; 
     }]; 
} 
0

viewDidLoad總是在對象顯示在屏幕前調用。 如果你想延遲一些,你可以在viewDidLoad或viewDidAppear中設置一些延遲代碼。但爲什麼你需要延遲,可能有其他解決方案來解決你的問題。

相關問題