我有3視圖控制器故事板:QuestionsTableViewController
,QuestionViewController
和AnswerViewController
如何解散多個視圖控制器?
對於所有密集的目的,QuestionsTableViewController
基本上是我主菜單。它有一個選擇的主題,當選擇填充QuestionViewController
問題標籤,然後被挑選。
用戶輸入的UITextField
他/她的答案,並點擊提交按鈕造成模態SEGUE到AnswerViewController
其中有一個返回無論是正確或不正確的消息,根據他們的答案進行比較的用戶標籤到編碼正確的答案。這個最終視圖控制器也有一個按鈕(回到菜單),點擊時,應將用戶帶回QuestionsTableViewController
(即我的菜單)。
這最後一部分(返回菜單)是我遇到問題的地方。
我可以多種方式解僱AnswerViewController
,但我無法弄清楚我需要做什麼才能將QuestionViewController
作爲這個按鈕的一部分。
我包括我的QuestionViewController
和AnswerViewController
類以下的snipets。
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
我沒有與故事板的經驗,但看到這一點:。http://stackoverflow.com/a/11381182/1430069 雖然這並沒有提到問題中的故事板,但我猜'view controller'的行爲是相同的。 – 2012-08-01 04:29:21