When I have a push segue from a UITableViewController to a regular view controller, the viewDidLoad method gets called twice. This makes the content on the second view controller to also appear twice. I thought that viewDidLoad was supposed to only be called once. Here is the code in which this happening.
viewDidLoad
-(void)viewDidLoad{
[super viewDidLoad];
//Change table view cell height if it is an ipad
UIDevice *device = [UIDevice currentDevice];
self.isiPad = (device.userInterfaceIdiom == UIUserInterfaceIdiomPad);
//Initialize the quiz
[self initializeTheQuiz];
}
Push Segue
- (IBAction)showQuiz:(id)sender{
UIButton *senderButton = (UIButton *)sender;
if (senderButton.tag <= 7 && senderButton.tag >= 0) {
[self performSegueWithIdentifier:@"showQuiz" sender:sender];
}else{
[self performSegueWithIdentifier:@"showFunFacts" sender:sender];
}
}
Here is how I perform the push segue
- (IBAction)showQuiz:(id)sender{
UIButton *senderButton = (UIButton *)sender;
if (senderButton.tag <= 7 && senderButton.tag >= 0) {
[self performSegueWithIdentifier:@"showQuiz" sender:sender];
}else{
[self performSegueWithIdentifier:@"showFunFacts" sender:sender];
}
}
//Prepare for segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIButton *senderButton = (UIButton *)sender;
//Set the quiz name based on the button
//Set the destination view controller
if ([segue.identifier isEqualToString:@"showQuiz"]) {
QuizViewController *quizViewController = (QuizViewController *)segue.destinationViewController;
if (senderButton.tag == 1) {
quizViewController.quizName = @"North America";
}else if (senderButton.tag == 2){
quizViewController.quizName = @"South America";
}else if (senderButton.tag == 3){
quizViewController.quizName = @"Africa";
}else if (senderButton.tag == 4){
quizViewController.quizName = @"Europe";
}else if (senderButton.tag == 5){
quizViewController.quizName = @"Asia";
}else if (senderButton.tag == 6){
quizViewController.quizName = @"Oceania";
}else if (senderButton.tag == 7){
quizViewController.quizName = @"Antarctica";
}
}else if ([segue.identifier isEqualToString:@"showFunFacts"]){
FunFactsTableViewController *funFactsViewController = (FunFactsTableViewController *)segue.destinationViewController;
if (senderButton.tag == 8) {
funFactsViewController.funFactsName = @"North America";
}else if (senderButton.tag == 9){
funFactsViewController.funFactsName = @"South America";
}else if (senderButton.tag == 10){
funFactsViewController.funFactsName = @"Africa";
}else if (senderButton.tag == 11){
funFactsViewController.funFactsName = @"Europe";
}else if (senderButton.tag == 12){
funFactsViewController.funFactsName = @"Asia";
}else if (senderButton.tag == 13){
funFactsViewController.funFactsName = @"Oceania";
}else if (senderButton.tag == 14){
funFactsViewController.funFactsName = @"Antarctica";
}
}
}