Reputation: 25
For some reason I am getting the above error when this view loads. The same code worked for populating tableView rows in my previous view, so I have no idea what could be going wrong in this one- it is the exact same code. The app crashes when I transition into this view. It manages to NSLog the categories in self.tableRows before crashing correctly, so storage in tableRows does not seem to be the problem. It is crashing on the line that counts the number of rows (return self.tableRows.count). I have a feeling the error has something to do with not being able to access tableRows, but I am very new to iOS. Thanks for your help! This is a project for a college class I have due soon so any help would be really appreciated.
#import "DivisionsViewController.h"
#import "TeamsViewController.h"
@implementation DivisionsViewController
@synthesize tableRows = _tableRows;
@synthesize currentKey = _currentKey;
NSMutableArray* temp;
#pragma mark - Table view data source
- (void)viewDidLoad
{
[super viewDidLoad];
_currentKey = @"default";
//temporary- trying to populate TableView from JSON
int i = -1;
self.tableRows = [NSMutableArray array];
temp = [[NSMutableArray alloc] init];
for(NSDictionary *dict in self.divisions){
NSString *category = [dict objectForKey:@"category"];
if (self.currentKey != category){
[self.tableRows addObject:category];
[temp addObject:[[NSMutableArray alloc] init]];
self.currentKey = category;
NSLog(@"table value %@", [self.tableRows lastObject]);
i++;
}
[[temp objectAtIndex:i] addObject:dict];
}
for (NSString* category in self.tableRows){
NSLog(@"category: %@", category);
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.tableRows.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DivisionCell" forIndexPath:indexPath];
cell.textLabel.text = [self.tableRows objectAtIndex:indexPath.row];
return cell;
}
Upvotes: 0
Views: 216
Reputation: 3547
self.tableRows = [NSMutableArray array];
This is an autorelease array now use this
self.tableRows = [[NSMutableArray array] retain];
or
self.tableRows = [NSMutableArray new];
Upvotes: 0
Reputation: 423
1 - currentKey is NSString? why doesn't using isEqualToString method?
self.currentKey != category
2 - and I have question about property type of 'tableRows' that exactly has property 'retain or strong'?
I hope your problem solved!
Upvotes: 0
Reputation: 362
Have you tried to NSLog your tablerows count? Try to NSlog it before it returns the numberOfRows.
self.tableRows.count
You can also try to set an exception breakpoint. In xcode choose the "breakpoint navigator" - its the second tab from the right in the tabs. (The tabs are where you can see your project in the left most tab) When you are in that tab, you can push the + in the left bottom -> Add exception breakpoint. Then it breaks right before it crashes - could be useful!
Upvotes: 1