开发者

EXC_BAD_ACCESS error when my view controller tries to access a singleton variable a second time

I have an app i building which is a simple naviagtion app. I do not want to load the data from my xml multiple times so I am using a singlet开发者_如何学编程on to load and hold the data. My first table pushes the view of the second table. This table calls the singleton and the get the array of data from there to display in the table.

This all works fine, I click on a cell in the first table which takes me to the second table where the singleton is used. I navigate back to the the first table, then back to the second table, this is when i get the EXC_BAD_ACCESS error. It doesn't error when i init the singleton but when I try and access the array in it. The code is as follows

MediaData *dataClass = [MediaData sharedManager];

//when i check in the singleton the second time sharedManager is already there

sortedData = dataClass.arrMediaData; //this line errors the second time

NSLog(@"sorted array. %@", sortedData);

[dataClass release];

Any help would be great as it is not a very descriptive error, thanks


The last line in your code is causing the issue. Singletons shouldn't be released.


As Jasarien said, don't release the singleton.

You can use NSZombieEnabled and run on a device to get more descriptive errors: http://www.cocoadev.com/index.pl?NSZombieEnabled

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜