I have a TableView that builds and draws ok, but then crashes on scrolling the view. I've run through the debugger and it appears that my class level variables are being overwritten somehow so they no longer exist when the titleForHeaderInSection is being called again. The very strange thing is that if I replace the code:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [favouritesDataSections objectAtIndex:section];
return sectionTitle;
}
with:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = @"Test";
return sectionTitle;
}
It still crashes but this time the debugger lists not an NSString when you hover over the sectionTitle variable.
This is the code I used to create the view and set up 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 going absolutely mad trying to track this down - spent 2 days on it so far so would be externally grateful for any help.
Best regards
Dave