我有一个带有 3 个视图控制器的故事板QuestionsTableViewController
:QuestionViewController
和AnswerViewController
对于所有密集的目的,QuestionsTableViewController
基本上是我的主菜单。it has a selection of topics which when selected populate a question label in QuestionViewController
which is then segued to.
用户在 a 中输入他/她的答案UITextField
并点击提交按钮,导致模态 segue到AnswerViewController
具有标签的标签,该标签基于他们的答案与编码的正确答案的比较向用户返回正确或不正确的消息。这个最终的视图控制器还有一个按钮(返回菜单),单击该按钮应将用户带回QuestionsTableViewController
(即我的菜单)。
最后一部分(返回菜单)是我遇到问题的地方。
我可以解除AnswerViewController
多种方式,但我无法弄清楚我需要做什么才能解除QuestionViewController
同一个按钮按下的一部分。
我在下面包括我的QuestionViewController
和AnswerViewController
课程的片段。
QuestionViewController.m
#import "QuestionViewController.h"
#import "AnswerViewController.h"
@interface QuestionViewController ()
@end
@implementation QuestionViewController
@synthesize currentQuestionDisplay;
@synthesize userAnswerTextField;
@synthesize currentQuestion;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
AnswerViewController *avc = [segue destinationViewController];
[avc setCurrentQuestion:currentQuestion];
[avc setUserAnswer:[userAnswerTextField text]];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.currentQuestionDisplay setText:[currentQuestion question]];
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[self setCurrentQuestionDisplay:nil];
[self setUserAnswerTextField:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)dismissKeyboard:(id)sender {
[userAnswerTextField resignFirstResponder];
}
- (void)dimissThisVC
{
[self dismissViewControllerAnimated:YES completion:^(void){}];
}
@end
AnswerViewController.m
#import "AnswerViewController.h"
#import "QuestionViewController.h"
@interface AnswerViewController ()
@end
@implementation AnswerViewController
@synthesize displayCurrentAnswer;
@synthesize currentQuestion;
@synthesize userAnswer;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
if([userAnswer isEqualToString:currentQuestion.answer]) {
[self.displayCurrentAnswer setText:@"You are correct!"];
}
else {
[self.displayCurrentAnswer setText:@"You are wrong!"];
}
// Do any additional setup after loading the view.
}
- (void)viewDidUnload
{
[self setDisplayCurrentAnswer:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)dismissAnswerVC:(id)sender {
[[self presentingViewController]
dismissViewControllerAnimated:YES
completion:^(void){ }];
}
@end