views:

288

answers:

2

My app crashes when I scroll the UITableView over the first cell or the last cell! Why this is happening? I add with addObject:name the objects of the UItableview . This is the code I use at cellForRowAtIndexPath. Help please! I have been trying to figure out what is going wrong hours!

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString * DisclosureButtonCellIdentifier = 
    @"DisclosureButtonCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: 
                             DisclosureButtonCellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                       reuseIdentifier: DisclosureButtonCellIdentifier]
                autorelease];
    }
    NSUInteger row = [indexPath row];

 NSString *rowString =nil;

    rowString = [list objectAtIndex:row];

 cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    [rowString release];
    return cell;
A: 

Is it throwing an exception - my guess is the index is not set:

rowString = [list objectAtIndex:row];

Can you set a breakpoint on this line and dump the "list"?

Mr-sk
+2  A: 

You are calling [rowString release]; but you never retained it.

Mike Weller
+1 about that release; not only you're never retaining it, if rowString is not nil, you might be releasing an autoreleased object, which is a very bad idea.
Adrian Kosmaczewski
Thank you so much! This was the problem! God bless you!
stefanosn