我在UITableView中遇到内存泄漏问题。如果我在DetailViewController表的底部,我想回到MasterViewController,我就崩溃了。如果我使用UITableViewController,则不会发生崩溃。
的AppDelegate
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor blackColor];
_window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[MasterViewController alloc] init]];
[_window makeKeyAndVisible];
MasterViewController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailViewController animated:YES];
}
DetailViewController
@interface DetailViewController ()
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.rowHeight = 60;
[self.view addSubview:_tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidScroll");
}
@end