开发者

Do UINavigationController buttons added need to be autoreleased? is this code ok?

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:

  1. Is code below correct?
  2. Any additional memory management code required elsewhere? (e.g. dealloc method? - I've currently got no code here to deallocate any buttons)
  3. 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";  
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜