开发者

Passing a dictionary from view controllers

开发者 https://www.devze.com 2022-12-14 21:07 出处:网络
In one of my Navigation view controllers I build an array of dictionaries to display in a table. Based on which one I select I then remove the dictionary from the array using

In one of my Navigation view controllers I build an array of dictionaries to display in a table. Based on which one I select I then remove the dictionary from the array using NSDictionary *notice = [notices objectAtIndex: roomIndex];

I create the new view controller using Feed *notice_view = [[Notice alloc] initWithObject: notice];

I push the navigation view controller and I've implemented initWithObject which takes a Dictionary.

I release the notice and notice_view and all this works fine but if I selected go back, select it go back about the third or forth time the whole app crashes. If I dont release both of them it works fine no problems what so ever, except of course the memory leaks.If i only release one of them, either of them, 开发者_开发百科it fails again. What gives? Should I not be using initWithObject or should I be passing it in some other way? I've also tried using autorelease but with the same result.


notice - you should not release, since you don't own the object(you are just using a object which is returned from NSArray) else retain this object when you retrieve the object from NSArray and release it later stage.

notice_view - as per you explanation I don't see any issue with releasing, I am assuming you don't have any reference to this object from other part of the code.


I'm guessing you'll want to get rid of [selectedNotice release], since there doesn't seem to be a corresponding -retain call in there.

0

精彩评论

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