Reputation: 1219
i have the following item to display in my table
redFlowers = [[NSMutableArray alloc] init];
[redFlowers addObject:@"red"];
and this is the way this array is supposed to be shown
#define sectionCount 2
#define redSection 0
#define blueSection 1
@synthesize tableFavoritesData, tableView, favoritesArray, redFlowers;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return sectionCount;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case redSection:
return [redFlowers count];
case blueSection:
return [tableFavoritesData count];
}
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case redSection:
return @"Refresh";
case blueSection:
return @"Favorites";
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
switch (indexPath.section)
{
case redSection:
cell.textLabel.text =[redFlowers objectAtIndex:indexPath.row];
case blueSection:
cell.textLabel.text = [tableFavoritesData objectAtIndex: indexPath.row];
}
return cell;
when i load my table it doesnt show at all the "red cell" from the redFlowers array but it shows the ones from tableFavoritesdata inside that section.
Upvotes: 0
Views: 121
Reputation: 523474
switch (indexPath.section)
{
case redSection:
cell.textLabel.text =[redFlowers objectAtIndex:indexPath.row];
break; // <--
case blueSection:
cell.textLabel.text = [tableFavoritesData objectAtIndex: indexPath.row];
break; // <--
}
If you don't break
, the red section case will fall through to the blue section case.
Upvotes: 1