Silver Challenge - weird problem with NSInteger

#1

So my idea is to create one more UITableViewCell using this code:

[code]- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

if (section == 0){
   
   return [[[CAJItemStore sharedStore] itemsOver50] count];
    
    
}else if (section == 1){
    return [[[CAJItemStore sharedStore] itemsUnder50]count];
}
return 0;
    
}[/code]

I did some research on doing math on NSInteger so here’s what I do: (a little messy here but makes sense to me)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0){
       
       NSInteger a = [[[CAJItemStore sharedStore] itemsOver50] count];
        NSInteger b = 1;
        NSInteger c = a + b;
        return c;
        
    }else if (section == 1){
        return [[[CAJItemStore sharedStore] itemsUnder50]count];
    }
    return 0;
        
    }

This one can be built succesfully but later it just crashed, with error like this:

Everything else works out quite well. I’ve tried this things a few times and every time I changed it back, it works again without crash. So I’m pretty sure this has something to do with dealing with NSInteger…
Any ideas here?

#2

[quote] ... NSInteger a = [[[CAJItemStore sharedStore] itemsOver50] count]; NSInteger b = 1; NSInteger c = a + b; return c; ... [/quote]
That can be simplified:

...
       return [[[CAJItemStore sharedStore] itemsOver50] count] + 1;
...

However, you will still get the Thread 1: signal SIGABRT error unless you make sure that you have one more item in your model to display in that section.