Can't find bug..advice?

Discussion in 'iOS Programming' started by GroundLoop, Sep 27, 2008.

  1. GroundLoop macrumors 68000

    GroundLoop

    Joined:
    Mar 21, 2003
    #1
    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
     
  2. ghayenga macrumors regular

    Joined:
    Jun 18, 2008
    #2
    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.
     

Share This Page