1

3 つのビュー コントローラーを含むストーリーボードがあります: QuestionsTableViewControllerQuestionViewControllerおよびAnswerViewController

すべての集中的な目的のために、QuestionsTableViewController基本的に私のメインメニューです。トピックの選択肢があり、選択すると質問ラベルが入力され、QuestionViewControllerそこに続きます。

ユーザーが に回答を入力しUITextField、サブミット ボタンを押すと、コード化された正解に対する回答の比較に基づいて、正解または不正解のメッセージをユーザーに返すラベルを持つへのモーダル セグエが発生します。AnswerViewControllerこの最後のView Controllerには、クリックするとユーザーがメニューに戻るボタン(メニューに戻る)もありますQuestionsTableViewController

この最後の部分 (メニューに戻る部分) は、私が問題を抱えている場所です。

複数の方法で閉じることができますが、この同じボタンを押したAnswerViewControllerときに閉じるために何をする必要があるかわかりません。QuestionViewController

以下に、私のクラスQuestionViewControllerAnswerViewControllerクラスのスニペットを含めます。

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
4

2 に答える 2

1

モーダルビューを閉じるときは、完了ブロックに次のコードを入力します。

[self.navigationController popViewControllerAnimated:YES];

または、最上位のコントローラーに移動する場合:

[self.navigationController popToRootViewControllerAnimated:YES];
于 2012-08-01T06:10:49.200 に答える
0

この投稿を参照する可能性のある他の人のためにこの投稿を完了するために、user523234 の回答をここに再投稿しています。

In the prepareForSegue method, you missed this line:

avc.delegate = self;

うまくいけば、これが私がいたのと同じ穴に落ちた他の誰かを助けることができます.

于 2012-08-04T01:06:37.773 に答える