UITableView crashes when scrolling

I have a TableView that builds and draws fine, but then crashes when I scroll the view. I went through the debugger, and it seems that my class level variables are somehow overwritten, so they no longer exist when the name ForHeaderInSection is called again. It is very strange that if I replaced the code:

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [favouritesDataSections objectAtIndex:section];
return sectionTitle;
}

from:

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = @"Test";
return sectionTitle;
}

It still crashes, but this time the debugger does not display an NSString when you hover over the sectionTitle variable.

This is the code I used to create the view and set the class level variables:

- (void)loadView {
[super loadView];
CGRect tableSize = CGRectMake(0,0,320,460);
UITableView *favouritesTableView = [[UITableView alloc] initWithFrame:tableSize style:UITableViewStylePlain];
favouritesTableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
favouritesTableView.dataSource = self;
favouritesTableView.delegate = self;
favouritesTableView.rowHeight = 52;
[self.view addSubview:favouritesTableView];
}

- (void)viewDidLoad {
[super viewDidLoad];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// Get the full path of the favourites plist
NSString *filename = [documentsDirectory stringByAppendingPathComponent:@"Favourites.plist"];
// Initialise Dictionary and array
favouritesDataAll = [[NSMutableDictionary alloc] init];
favouritesDataSections = [[NSArray alloc] init];

NSDictionary *dict = [[[NSMutableDictionary alloc] initWithContentsOfFile:filename] retain];
favouritesDataAll = dict;
[dict release];

favouritesDataSections = [favouritesDataAll allKeys];   
}

I am absolutely insane, trying to track this, I spent 2 days on it, so I would be grateful for any help.

Regards

Dave

+5
3

, ...

favouritesDataSections = [favouritesDataAll allKeys];

To:

favouritesDataSections = [[favouritesDataAll allKeys] retain];

. , , , , - , barfing .

, " " , ( , , ). , - /, , ( , ..) .

, Dave

+12

@property, , , , , :

self.favoritesDataSection

@property () , "", , .

+4

Looks like some corruption of memory is going on here.

One thing that I see is that those calls [super ...] should occur after other code in these methods.

What happens if you customize your tabular view to only one partition?

0
source

All Articles