关于一个简单的学生列表app的问题 tableVIew数据通信app 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先,你的delegate要用weak或者assign,用strong会导致循环引用。currentStudent的问题,最好把StudentDetailsVIewController这个类贴出来看一下。 这是.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];} 应该是你没有传值给currentStudent属性,需要把StudentListTableViewController相关代码贴出来 你是用的Storyboard吗?我在你的didSelect方法里面没看到pushViewController,如果你是用的Storyboard,要在prepareForSegue里面处理,就像这样:-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UITableViewCell *)cell{ ViewController *destVC = (ViewController *)segue.destinationViewController; destVC.currentStudent = chosenStudent;} 如下图,把strong改成retain 还有你的代理应该是assign的@property (nonatomic, assign) id <StudentDetailsViewControllerDelegate> delegate; 把哪个属性的strong改成retain? 把哪个属性的strong改成retain?ARC环境下,strong = retain 我用的是storyboard用你的方法我终于成功解决了问题,但是我之前照着书上做书上的例子,并没有用prepareForSegue,而是像我之前的那样,也成功了 如何下架已上传的appStore应用 obj-c的一个小问题 新手求助 苹果公司的硬件平台是自己设计的么? UICollection using Swift 为什么[UIImagePickerController isSourceTypeAvailable的值为NO 关于IOS录音并且发送的问题 iOS textView.attributedText 插入NSTextAttachment显示图片后内存泄漏 Objective-C 中怎么生成numbers文件 游戏APP通过脚本用企业证书签名过程太慢 mac应用程序开发问题,怎么在自己代码里控制另一个app应用。 新人,求教OC语法相关
#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];
}
ViewController *destVC = (ViewController *)segue.destinationViewController;
destVC.currentStudent = chosenStudent;
}
@property (nonatomic, assign) id <StudentDetailsViewControllerDelegate> delegate;
ARC环境下,strong = retain