How to automatically change/transit from one view to another, without pushing a button or any action, just after some time, say 2,3 seconds in Xcode/Objective-C, how would the code look like, and where to write it?
How to automatically change/transit from one view to another, without pushing a button or any action
Asked
Active
Viewed 77 times
0
1 Answers
0
The basic solution might look like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// create and position the subviews, if necessary
self.subview1 = ...
self.subview2 = ...
self.view addSubview:self.subview1];
self.view addSubview:self.subview2];
}
- (void)viewWillAppear
{
[super viewWillAppear];
[self showFirstView];
}
- (void)showFirstView
{
self.subview1.hidden = NO;
self.subview2.hidden = YES;
[self performSelector:@selector(showSecondViewView) withObject:nil afterDelay:5];
}
- (void)showSecondViewView
{
self.subview1.hidden = YES;
self.subview2.hidden = NO;
}

TotoroTotoro
- 17,524
- 4
- 45
- 76
-
If he's talking about having it happen after 2-3 seconds he would want to use `[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(showSecondView) userInfo:nil repeats:NO];` in `viewDidLoad` or `viewWillAppear`. – AdamPro13 Oct 16 '14 at 16:43
-
Sure, that's what my code does. The initial state (created by showFirstView) will stay for 5 seconds after the view controller appears, then secondView will appear instead. – TotoroTotoro Oct 16 '14 at 17:17
-
Whoops, didn't scroll all the way over. Good call. – AdamPro13 Oct 16 '14 at 18:07