Ios 解除多个视图控制器的委派问题

Ios 解除多个视图控制器的委派问题,ios,uiviewcontroller,uitableview,modalviewcontroller,Ios,Uiviewcontroller,Uitableview,Modalviewcontroller,我以前问过一个关于取消多视图控制器的问题,我得到的答案以及我在其他地方找到的可能解决方案都没有达到预期效果。我已经把我的问题缩小到我组建代表团的方式上。下面是代码,如果有任何反馈,我将不胜感激 我的完整项目可在此处下载: 谢谢 // // QuestionViewController.h // learningTheRopes1 // // Created by James Ulle on 7/18/12. // Copyright (c) 2012 __MyCompanyName__.

我以前问过一个关于取消多视图控制器的问题,我得到的答案以及我在其他地方找到的可能解决方案都没有达到预期效果。我已经把我的问题缩小到我组建代表团的方式上。下面是代码,如果有任何反馈,我将不胜感激

我的完整项目可在此处下载:

谢谢

//
//  QuestionViewController.h
//  learningTheRopes1
//
//  Created by James Ulle on 7/18/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "Question.h"
#import "AnswerViewController.h"

@interface QuestionViewController : UIViewController <AnswerViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UILabel *currentQuestionDisplay;

@property (weak, nonatomic) IBOutlet UITextField *userAnswerTextField;

@property (nonatomic, strong) Question *currentQuestion;

- (IBAction)dismissKeyboard:(id)sender;

- (void)dismissQVC;

@end

    //
    //  QuestionViewController.m
    //  learningTheRopes1
    //
    //  Created by James Ulle on 7/18/12.
    //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
    //

    #import "QuestionViewController.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)dismissQVC {
    NSLog(@"Dismiss QVC");
    [self.navigationController popViewControllerAnimated:NO];
}

@end

    //
//  AnswerViewController.h
//  learningTheRopes1
//
//  Created by James Ulle on 7/18/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "Question.h"

@protocol AnswerViewControllerDelegate <NSObject>
- (void)dismissQVC;
@end

#import "QuestionViewController.h"

@interface AnswerViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *displayCurrentAnswer;

@property (nonatomic, strong) Question *currentQuestion;

@property (nonatomic, strong) NSString *userAnswer;

@property (nonatomic, weak) id <AnswerViewControllerDelegate> delegate;

- (IBAction)dismissAnswerVC:(id)sender;

@end

    //
//  AnswerViewController.m
//  learningTheRopes1
//
//  Created by James Ulle on 7/18/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AnswerViewController.h"

@interface AnswerViewController ()

@end

@implementation AnswerViewController

@synthesize displayCurrentAnswer;
@synthesize currentQuestion;
@synthesize userAnswer;
@synthesize delegate;


- (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 dismissViewControllerAnimated:YES completion:^{

        NSLog(@"Dismiss AVC");
        [[self delegate] dismissQVC];

    }];

}

@end

在prepareForSegue方法中,您错过了这一行:


avc.delegate=self

谢谢你。非常感谢。非常感谢。我是iOS的新手,代表团把我难住了。就像我现在想要的那样。
2012-08-03 19:04:34.235
learningTheRopes1[4165:f803] Dismiss AVC