Do UINavigationController buttons added need to be autoreleased? is this code ok?
Background - I'm seeing a range of navigation issues occuring in my application after I start triggering "memory warnings". I'm wondering if it is something to do开发者_高级运维 with the question I posed here. Questions would include:
- Is code below correct?
- Any additional memory management code required elsewhere? (e.g. dealloc method? - I've currently got no code here to deallocate any buttons)
- Any other tips re what might be going wrong with navigation bar populations/screen flow issues using a UINavigationController after simulating memory warnings
Code Below:
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = [
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction:)] autorelease]; // IS AUTORELEASE HERE CORRECT?
self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.title = @"Views";
thanks
I always just use autorelease and I think that it should do just fine.
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction:)]; // IS AUTORELEASE HERE CORRECT?
self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.title = @"Views";
}
精彩评论