我使用Xcode模板创建了Master-Detail应用程序,我正在使用Core Data。我用仪器(内存泄漏)检查应用程序,当从详细信息视图返回到主视图时,我看到内存泄漏。
I:
时会出现内存泄漏我的代码:
MasterViewController.m:
@implementation MasterViewController
.....
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Event *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];
}
}
DetailViewController.h:
#import <UIKit/UIKit.h>
#import "Event.h"
@interface DetailViewController : UIViewController <UITextViewDelegate>
@property (strong, nonatomic) Event *detailItem;
@end
DetailViewController.m:
- (IBAction)clickSave:(id)sender {
self.detailItem.myText = self.textView.text;
NSError *error;
if (![self.detailItem.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}