UITableView IndexPathForCell return errors
In my UITableView, each cell has a custom UISwitch. I am saving the switch information in an NSMutableArray, with the intent of using it to save the state information whenever the user changes to a different table.
To do this, I need to obtain the row information of the cell, so that I can flip the corresponding "YES" or "NO" in the NSMutableArray. I attempt to do it as such:
UICustomSwitch *temp = (UICustomSwitch *)sender;
UITableViewCell *cell = (UITableViewCell *)temp.superview;
NSIndexPath *path = [self.tableView indexPathForCell:cell];
After this I have
NSLog(@"Path was: %@", path);
Now, when I output path, I get something like:
Path was: <N开发者_C百科SIndexPath 0x4b25590> 2 indexes [0, 1]
However, when I change the NSlog to path.row, the program crashes. I've not found a reason for this, and I use path.row in other places as well. Can anyone help explain why this is happening?
Edit:
For example, when I do this:
NSLog(@"Path was: %d", path.row);
It crashes.
NSIndexPath.row
returns a plain unsigned integer (NSUInteger
), not an object, so you'll need to change your NSLog
format specifier to from %@
to %u
. By using %@
, it's using the integer as a memory address, which very likely points to some memory that is not an object at all.
Did you try :
NSLog(@"Path was: %@", path.row);
? path.row
is type of NSUInteger
. You could use '%d' instead of '%@'.
Uhm... I'm not sure this counts as an answer, but I ended up restarting the computer and it started working again. So... Yeah, I really have no idea what in the world was going on.
精彩评论