I have an indexPath.row that is 1 and logs 1(when using NSLog). If I call indexPath.row-1 (should return 0) it returns 4294967295.
I’m trying to return an objectAtIndex:indexPath.row-1 but that’s when I get 4294967295.
Any ideas?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
Singleton *singleton = [Singleton sharedSingleton];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([[prefs objectForKey:@"isYes"]boolValue] == 1 && randomMarker != 100)
{
//sets cell image
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,98,100)];
imgView.image = [UIImage imageNamed:@"stackoverflow.png"];
cell.imageView.image = imgView.image;
//sets cell text
cell.textLabel.text = @"Text";
self.checkedInCount == 100;
}
else if ([[prefs objectForKey:@"isYes"]boolValue] == 1 && randomMarker == 100)
{
//gets cell and cleans up cell text
NSLog(@"%@", indexPath.row);
NSString *title = [[[singleton linkedList]objectAtIndex:(indexPath.row-1)]objectForKey:@"desc"];
When you attempt to give an unsigned int (
NSUInteger) a negative value, it often returns a very large positive value instead.You are calling
when
indexPath.rowhas value0, so the translation is:Since
objectAtIndex:takes an unsigned integer as its parameter,-1is converted to a garbage value of4294967295.To avoid this problem, don’t subtract
1from0by checking first thatindexPath.rowis positive.Here’s another problem:
This should instead read: