开发者

Accessing Problem with NSDictionary

I have following problem: I have a NSDictionary here:

@interface ENSListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
NSDictionary* ensList;
}

@property (nonatomic, retain) IBOutlet NSDictionary* ensList;
开发者_JAVA技巧

Now I have a UITableView which I want to set the Number or rows here:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
[self LoadENSList];
NSLog(@"%@", ensList); //Crash Bad Exec
return 2000;
}

I load the ENSList here:

- (void) LoadENSList
{
    if (ensList == nil)
    {
        NSDictionary *ensListFirstReturn = [ENSHandler GetENSListForFolderType:folder_type andFolderID:folder_id];
        BOOL success = [[ensListFirstReturn objectForKey:@"success"] boolValue];  
        if (success)
        {
            ensList = [ensListFirstReturn objectForKey:@"return"];
            NSLog(@"%@", ensList);
        }
        else
        { 
            [MyAlert ShowSimpleAlert:@"Fehler" andText:@"ENS-Ordner-Liste konnte nicht geladen werden"];
        }
    }
}

Now my problem:

The enlist is loaded correct at the first place. The first "NSLOG()" gives me all correct data. As sool as the method LoadENSList ends, the ensList seems to have problems, because I got a BAD EXE-Error at the second NSLOG().

Why?


In this line:

ensList = [ensListFirstReturn objectForKey:@"return"];

You don't use the property accessor. This means that the array is autoreleased and no longer exists during the next event loop.

You need to change it to this:

self.ensList = [ensListFirstReturn objectForKey:@"return"];


Seems to be a problem of memory management..

Try

ensList = [[ensListFirstReturn objectForKey:@"return"] copy];

in loadENSList.

MfG,

SIdeSwipe

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜