I have a problem with counting numbers of object in nsmutablearray. I have this code:
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
NSUInteger numObjects = [selected count];// selected is nsmutablearray
for ( int i = 0; i<numObjects; i++)
{
NSLog(@"%@ == %@ , nr.object =%@",[AnotherArray objectAtIndex:indexPath.row], [selektuara objectAtIndex:i], numObjects); // here stops the by reporting this: Program recived signal: "EXC_BAD_ACCESS"
if ([selected objectAtIndex:i] == [AnotherArray objectAtIndex:indexPath.row])
{
NSLog(@"%@",[selected objectAtIndex:i]);
return UITableViewCellAccessoryCheckmark;
}
else
{
return UITableViewCellAccessoryNone;
}
}
}
When i remove NSLog for numbers of object, it counts only one object and compare only that.
So has anyone else another solution how to get this number?
Thanks.
Error in using
NSLog:As
numObjectsisNSUIntegeryou should use%dto print its value.Error in comparing:
You shouldn’t use
==for comparing objects in Objective-C