Welcome, Guest
Username Password: Remember me

EXC_BAD_ACCESS with Cell creatuon
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: EXC_BAD_ACCESS with Cell creatuon

EXC_BAD_ACCESS with Cell creatuon 1 year, 2 months ago #1

I have the following code that causes me issues, even if I don't release the Array or the object I still get issues. Is this not the right way of doing this?

The table view loads all the data fine but if I try scrolling or clicking on one of the cells that is where I get the issue. If I just leave it alone the app does not crash.

The crash is on the following line in SCGlobal.m
[valuesArray addObject:value];


And here is my code

db = [FMDatabase databaseWithPath:databasePath];
if (![db open]) {
NSLog(@"Could not open db.");
}
 
FMResultSet *rs;
if (self.RootID == nil){
rs = [db executeQuery:@"select rowid,* from DB where RootID IS NULL"];;
}else{
rs = [db executeQuery:@"select rowid,* from DB where RootID = ?", [self.RootID stringValue]];
}
 
NSMutableArray *itemsArray = [[NSMutableArray alloc] init];
 
while ([rs next]) {
MenuObject *tempObject = [[MenuObject alloc] initWithItemID:[NSNumber numberWithInt:[rs intForColumn:@"RootID"]] title:[rs stringForColumn:@"Name"] content:[rs stringForColumn:@"Content"]];
[itemsArray addObject:tempObject];
[tempObject release];
tempObject = nil;
}
 
 
if ([db hadError]) {
NSLog(@"Err %d: %@", [db lastErrorCode], [db lastErrorMessage]);
}
 
 
self.clearsSelectionOnViewWillAppear = YES;
 
tableModel = [[SCTableViewModel alloc] initWithTableView:self.tableView withViewController:self];
 
SCClassDefinition *taskClassDef = [SCClassDefinition definitionWithClass:[MenuObject class]
withPropertyNames:[NSArray arrayWithObjects:@"title", @"itemID",@"content", nil]];
 
SCArrayOfObjectsSection *tasksSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil withItems:itemsArray withClassDefinition:taskClassDef];
tasksSection.allowEditDetailView = FALSE;
[tableModel addSection:tasksSection];
 
[itemsArray release];
  • lesmond
  • OFFLINE
  • Junior Boarder
  • Posts: 24
  • Karma: 1
Last Edit: 1 year, 2 months ago by lesmond.

Re: EXC_BAD_ACCESS with Cell creatuon 1 year, 2 months ago #2

Hi Lee,

Your code looks perfectly fine to me. Are you able to send me this project (at our support email) to do some further debugging?
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72

Re: EXC_BAD_ACCESS with Cell creatuon 1 year, 2 months ago #3

Thanks Tarek,

I actually managed to get to the bottom of it. The accessories for the title in my MenuObject was set to (nonatomic,assign) which is usually fine but changning to (nonatomic,copy) sorted it.

Lee
  • lesmond
  • OFFLINE
  • Junior Boarder
  • Posts: 24
  • Karma: 1

Re: EXC_BAD_ACCESS with Cell creatuon 1 year, 2 months ago #4

Hi Lee,

This actually makes a lot of sense. Any NSString property set to a string literal (e.g.: @"string") must be defined as a copy or retain property, as @"string" will be autoreleased leaving the property pointing to a deallocated memory address (zombie).
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2402
  • Karma: 72
  • Page:
  • 1
Time to create page: 1.64 seconds