My problem is that I have a UITable, and I cannot get the numberOfRowsInSection to correspond with cellForRowAtIndexPath.
My foodCategoryObj has three arrays, first array has 6 elems, second has 2 and third has 3.
This line
FoodCategory *foodCategoryObj = [appDelegate.foodCategoryArray objectAtIndex:indexPath.row];
..keeps throwing this error.. index 2 beyond bounds [0 .. 1]
Overall I do not know what number to return for numberOfRowsInSection
Also arrayCountInt returns number of objects in the array I have created in viewWillAppear.
- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section {
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *arrayCountString = [prefs stringForKey:@"arrayCountString"];
NSInteger *arrayCountInt = [arrayCountString intValue];
//NSLog(@"arrayCountInt.. %i", (arrayCountInt) - 1);
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSInteger *arrayCount = [appDelegate.foodCategoryArray count];
NSInteger *foodArray = [foodCatArray count];
// testing
NSLog(@"foodCatArray.. %i", foodArray);
return arrayCountInt;
}
- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
//NSLog(@"indexPath.row.. %i", (indexPath.row)-1);
FoodCategory *foodCategoryObj = [appDelegate.foodCategoryArray objectAtIndex:indexPath.row];
//Set the cell title
cell.text = foodCategoryObj.foodName;
// testing
//NSLog(@"%@", foodCategoryObj.foodName);
//NSLog(@"appDelegate.foodCategoryArray.. %@", appDelegate.foodCategoryArray);
return cell;
}
why don’t you return
[appDelegate.foodCategoryArray count]in thenumberofrowInSectionmethod. You should return yourfoodArrayand you return the wrong var