解决方案 »

  1.   

    首先,你的delegate要用weak或者assign,用strong会导致循环引用。currentStudent的问题,最好把StudentDetailsVIewController这个类贴出来看一下。
      

  2.   

    这是.h文件里的:#import <UIKit/UIKit.h>
    #import "Student.h"@class StudentDetailsViewController;@protocol StudentDetailsViewControllerDelegate <NSObject>- (void)studentDetailsViewControllerDidFinish:(StudentDetailsViewController *)sender;@end@interface StudentDetailsViewController : UIViewController<UITextFieldDelegate>@property (strong, nonatomic) Student *currentStudent;@property (weak, nonatomic) IBOutlet UITextField *classNameTextField;
    @property (weak, nonatomic) IBOutlet UITextField *nameTextField;
    @property (weak, nonatomic) IBOutlet UITextField *numberTextField;@property (weak, nonatomic) id<StudentDetailsViewControllerDelegate>delegate;- (IBAction)revert:(id)sender;
    @end这是.m文件里的:#import "StudentDetailsViewController.h"@interface StudentDetailsViewController ()@end@implementation StudentDetailsViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }- (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view.    
    }- (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    - (IBAction)revert:(id)sender {
        [self populateViewWithStudent:self.currentStudent];
    }
    // Populate the data
    - (void)populateViewWithStudent:(Student *)student
    {
        self.currentStudent = student;
        
        self.classNameTextField.text = student.className;
        self.nameTextField.text = student.name;
        self.numberTextField.text = student.number;
    }- (void)viewWillAppear:(BOOL)animated
    {
        [self populateViewWithStudent:self.currentStudent];
    }- (void)viewWillDisappear:(BOOL)animated
    {
        [self.view.window endEditing:YES];
        
        self.currentStudent.name = self.nameTextField.text;
        self.currentStudent.className = self.classNameTextField.text;
        self.currentStudent.number = self.numberTextField.text;
        [self.delegate studentDetailsViewControllerDidFinish:self];
    }
      

  3.   

    应该是你没有传值给currentStudent属性,需要把StudentListTableViewController相关代码贴出来
      

  4.   

    你是用的Storyboard吗?我在你的didSelect方法里面没看到pushViewController,如果你是用的Storyboard,要在prepareForSegue里面处理,就像这样:-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)cell{
        ViewController *destVC = (ViewController *)segue.destinationViewController;
        destVC.currentStudent = chosenStudent;
    }
      

  5.   

    如下图,把strong改成retain
      

  6.   

    还有你的代理应该是assign的
    @property (nonatomic, assign) id <StudentDetailsViewControllerDelegate> delegate;
      

  7.   

    把哪个属性的strong改成retain?
      

  8.   

    把哪个属性的strong改成retain?
    ARC环境下,strong = retain
      

  9.   

    我用的是storyboard用你的方法我终于成功解决了问题,但是我之前照着书上做书上的例子,并没有用prepareForSegue,而是像我之前的那样,也成功了