iphone表视图混合部分中的项目

时间:2010-08-24 07:44:44

标签: iphone

我在表格中显示以下项目

redFlowers = [[NSMutableArray alloc] init];
    [redFlowers addObject:@"red"];

这就是这个数组应该显示的方式

#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;

当我加载我的表时,它不显示redFlowers数组中的所有“红色单元格”,但它显示了该部分中tableFavoritesdata中的那些。

1 个答案:

答案 0 :(得分:1)

switch (indexPath.section) 
{
    case redSection:
        cell.textLabel.text =[redFlowers objectAtIndex:indexPath.row];
        break;     // <--
    case blueSection:
        cell.textLabel.text = [tableFavoritesData objectAtIndex: indexPath.row];
        break;     // <--
}

如果你没有break,红色部分的情况将会落到蓝色部分。

相关问题