29,028
社区成员
发帖
与我相关
我的任务
分享
@property (nonatomic, assign) id <StudentDetailsViewControllerDelegate> delegate;
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)cell{
ViewController *destVC = (ViewController *)segue.destinationViewController;
destVC.currentStudent = chosenStudent;
}
#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];
}