2010-08-24 16 views
0

我有以下項在我的表中顯示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
switch (indexPath.section) 
{ 
    case redSection: 
     cell.textLabel.text =[redFlowers objectAtIndex:indexPath.row]; 
     break;  // <-- 
    case blueSection: 
     cell.textLabel.text = [tableFavoritesData objectAtIndex: indexPath.row]; 
     break;  // <-- 
} 

如果不這樣做break,紅色部分情況下都將落空,以藍色的部分情況。

+0

非常感謝 – 2010-08-24 08:11:54