开发者

Releasing a navigationItem

开发者 https://www.devze.com 2023-04-01 12:28 出处:网络
I\'ve the following question: I\'ve an AppDelegate and I add there a navigationController and load UIViewController B in it.

I've the following question:

I've an AppDelegate and I add there a navigationController and load UIViewController B in it.

In B I add a navigationItem, a leftBarButtonItem or a rightBarButtonItem.

Where do I have to release these items, because I alloc and init them in B. So at the first I thought about releasing self.navigationItem.rightBarButtonItem in Dealloc-Method of B.

But if I'm analyzing my app, the analyzer says at the release-position in B's dealloc-method:

Incorrect decrement of the reference count of an object that is not owned at this point by the caller.

But I don't understad what I've done wrong or is everything ok 开发者_Go百科and it's an analyzer problem?

Can somebody help me finding out?

Greets andi1984


As soon as you allocate and assign to rightBarButtonItem you can release like

UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showNewEventViewController)];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
[rightBarButtonItem release];

Similarly to leftBartButtonItem

self.navigationItem.rightBarButtonItem might have a retain in itself and knows when to release that count.

0

精彩评论

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