Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

GroundLoop

macrumors 68000
Original poster
Mar 21, 2003
1,586
62
I am having a problem locating a bug in my code. Here is an exerpt:

Code:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) {
        // Create a new cell. CGRectZero allows the cell to determine the appropriate size.
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
    }
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    Store *store = (Store *)[appDelegate.stores objectAtIndex:indexPath.row];
    cell.text = store.storeName;
    return cell;
}

It crashes at the "cell.text = store.storeName;" line. I have noticed that when I print out storeName at initialization, it is fine. So it is reading the string from the SQLite DB. I also checked the string right after I released the original Store object (after storing it in the appDelegate's "stores" NSMutableArray)

But what I try to print the string within the function above, it dies a horrible death.

I am using the SQLite Books sample code as a model, and that project runs just fine. I am stumped. Anybody have any ideas where the storeName NSString may be getting hosed?

Thanks,
Hickman
 
I am having a problem locating a bug in my code. Here is an exerpt:

Code:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) {
        // Create a new cell. CGRectZero allows the cell to determine the appropriate size.
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"MyIdentifier"] autorelease];
    }
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    Store *store = (Store *)[appDelegate.stores objectAtIndex:indexPath.row];
    cell.text = store.storeName;
    return cell;
}

It crashes at the "cell.text = store.storeName;" line. I have noticed that when I print out storeName at initialization, it is fine. So it is reading the string from the SQLite DB. I also checked the string right after I released the original Store object (after storing it in the appDelegate's "stores" NSMutableArray)

But what I try to print the string within the function above, it dies a horrible death.

I am using the SQLite Books sample code as a model, and that project runs just fine. I am stumped. Anybody have any ideas where the storeName NSString may be getting hosed?

Thanks,
Hickman

Odds are you didn't retain it when you created it and by the time the table is trying to display it it doesn't exist anymore. Just a guess.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.