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
The
rowmethod ofNSIndexPathreturns aNSInteger.That’s a primitive type, not an object.
So you can’t print it using
%@.What you want is:
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.