0

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.

2 Answers 2

2

Error in using NSLog:

NSLog(@"%@ == %@ , nr.object =%d",[AnotherArray objectAtIndex:indexPath.row], [selektuara objectAtIndex:i], numObjects);

As numObjects is NSUInteger you should use %d to print its value.

Error in comparing:

if ([[selected objectAtIndex:i] compare:[AnotherArray objectAtIndex:indexPath.row]] == NSOrderedSame)

You shouldn't use == for comparing objects in Objective-C

Sign up to request clarification or add additional context in comments.

2 Comments

Thnx a lot, now i have that number, but i have another problem here at loop at return, that doesn't let me to compare other object, it only compares the first object and then returns UITableViewCellAccessoryNone;
So don't return when you found equal
1

You must not try to output an unsigned integer with the %@ format specifier. Use %u instead.

1 Comment

Do you know how can i do here to "remember" the checked cells before, i save checked cells text in the object "selected"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.