问题描述:

I have following problem:

I have a NSDictionary here:

@interface ENSListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

{

NSDictionary* ensList;

}

@property (nonatomic, retain) IBOutlet NSDictionary* ensList;

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

相关阅读:
Top