現在、ナビゲーション ベースのアプリケーションがあり、明らかに RootViewController は UITableView です。ただし、UITableView の上に浮かぶ UIToolbar を作成する必要があると判断しました。現在、私はこれをこのようにしています。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Initialize the toolbar
toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;
//Set the toolbar to fit the width of the app.
[toolbar sizeToFit];
//Caclulate the height of the toolbar
CGFloat toolbarHeight = [toolbar frame].size.height;
//Get the bounds of the parent view
CGRect rootViewBounds = self.parentViewController.view.bounds;
//Get the height of the parent view.
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
//Get the width of the parent view,
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
//Create a rectangle for the toolbar
CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);
//Reposition and resize the receiver
[toolbar setFrame:rectArea];
//Create a button
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(account_details)];
[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
//Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];
[infoButton release];
[self.tableView reloadData];
}
しかし、Leaks インストゥルメント ツールを使用した後、これがいくつかのメモリ リークの原因であると判断できました。それにもかかわらず、メモリ リークはごくわずかでした。次に、さらに掘り下げて、メモリ リークの原因となっている正確な行を特定することができました。それらは次のとおりです。
UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(account_details)];
[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];
[self.navigationController.view addSubview:toolbar];
これらのメモリ リークを取り除く方法を見つけ出すのに苦労しているため、アプリケーションがよりスムーズに実行されます。上記の行がリークを引き起こしている理由について、何か助けていただければ幸いです。