3 つのビュー コントローラーを含むストーリーボードがあります: QuestionsTableViewController
、QuestionViewController
およびAnswerViewController
すべての集中的な目的のために、QuestionsTableViewController
基本的に私のメインメニューです。トピックの選択肢があり、選択すると質問ラベルが入力され、QuestionViewController
そこに続きます。
ユーザーが に回答を入力しUITextField
、サブミット ボタンを押すと、コード化された正解に対する回答の比較に基づいて、正解または不正解のメッセージをユーザーに返すラベルを持つへのモーダル セグエが発生します。AnswerViewController
この最後のView Controllerには、クリックするとユーザーがメニューに戻るボタン(メニューに戻る)もあります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