I have a very basic application in which a second ViewController is instantiated if the conditions of an 'if' statement are true. Upon loading of the second ViewController, the methods of the first ViewController still run. I need all previous methods to stop for the application to run correctly.
// In FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
{
NSTimeInterval beginTouchTime;
NSTimeInterval endTouchTime;
NSTimeInterval touchTimeInterval;
}
@property (nonatomic, readonly) NSTimeInterval touchTimeInterval;
- (void) testMethod;
@end
// In FirstViewController.m
#import "FirstViewController.h"
#import "SecondViewController.h"
@implementation FirstViewController
@synthesize touchTimeInterval;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void) testMethod
{
if (touchTimeInterval >= 3)
{
NSLog(@"Go to VC2");
SecondViewController *secondBViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self presentViewController:secondViewController animated:YES completion:nil];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
beginTouchTime = [event timestamp];
NSLog(@"Touch began");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
endTouchTime = [event timestamp];
NSLog(@"Touch ended");
touchTimeInterval = endTouchTime - beginTouchTime;
NSLog(@"Time interval: %f", touchTimeInterval);
[self testMethod]; // EDIT: USED TO BE IN viewDidLoad
}
@end
The second screen successfully loads but the log messages persist, meaning that the methods of FirstViewController still occur, although in the view of the SecondViewController. What am I doing wrong?