导致 viewDidLoad 运行
Cause viewDidLoad to run
我正在创建一个新的 UIViewController
,但要等几秒钟才能显示它。
问题是我希望 viewDidLoad
在我实际显示 now 对象之前被调用。我怎样才能使 viewDidLoad
运行?
目前我正在做这样的事情:
UIView *tempView = newObject.view;
但我真的不喜欢那个解决方案。
如果有您想要 运行 在实例化视图时调用的代码,那么只需将其放在 init
方法中即可。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName: nibNameOrNil
bundle: nibBundleOrNil];
if (self)
{
// Custom stuff
}
return self;
}
您希望 viewDidLoad
被调用还有其他原因吗?
看起来只要调用 [newObject view];
就可以了!
- (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;
}];
}];
}
viewDidLoad 总是在对象显示在屏幕上之前被调用。
如果你想要一些延迟,你可以在 viewDidLoad 或 viewDidAppear 中设置一些延迟代码。但为什么你需要延迟,可能有其他解决方案可以解决你的问题。
我正在创建一个新的 UIViewController
,但要等几秒钟才能显示它。
问题是我希望 viewDidLoad
在我实际显示 now 对象之前被调用。我怎样才能使 viewDidLoad
运行?
目前我正在做这样的事情:
UIView *tempView = newObject.view;
但我真的不喜欢那个解决方案。
如果有您想要 运行 在实例化视图时调用的代码,那么只需将其放在 init
方法中即可。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName: nibNameOrNil
bundle: nibBundleOrNil];
if (self)
{
// Custom stuff
}
return self;
}
您希望 viewDidLoad
被调用还有其他原因吗?
看起来只要调用 [newObject view];
就可以了!
- (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;
}];
}];
}
viewDidLoad 总是在对象显示在屏幕上之前被调用。 如果你想要一些延迟,你可以在 viewDidLoad 或 viewDidAppear 中设置一些延迟代码。但为什么你需要延迟,可能有其他解决方案可以解决你的问题。