Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EXC_BAD_ACCESS in [indexPath row]

I am customizing my table cells. I have this code (simplified) which is giving me an EXC_BAD_ACCESS when trying to access [indexPath row]

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"WCFPictureCell";
    static NSString *CellNib = @"WCFPictureCell";
    WCFPictureCell *cell = (WCFPictureCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
        cell = (WCFPictureCell *)[nib objectAtIndex:0];
    }
    NSLog(@"iph    %@", indexPath);
    NSLog(@"iphrow %@", [indexPath row]);
    return cell;
}

What am I doing wrong?

Thanks

like image 557
Marc Avatar asked Nov 27 '25 16:11

Marc


1 Answers

The row method of NSIndexPath returns a NSInteger.
That's a primitive type, not an object.

So you can't print it using %@.

What you want is:

NSLog( @"iphrow %i", [ indexPath row ] );

You are getting a segmentation fault because %@ is used for a pointer to an object.
As you are passing an integer, NSLog will try to print an object at the memory address specified by the integer value.

like image 120
Macmade Avatar answered Nov 30 '25 06:11

Macmade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!