根據

2011-08-23 66 views
0

以下代碼正常工作,應用不同的單元格屬性,但它將相同的單元格文本應用於所有部分。我怎樣才能應用選擇案例也取決於部分?謝謝。根據

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   
    } 

    switch (indexPath.row) { 
     case 0: 
      cell.textLabel.text = @"English"; 
      break; 
     case 1: 
      cell.textLabel.text = @"Chinese"; 
      break; 
     case 2: 
      cell.textLabel.text = @"Japanese"; 
      break; 
     default: 
      break; 
    } 

    return cell; 
} 

回答

1

您可以使用indexPath.section得到部分號碼,就像您如何使用indexPath.row的行號。

0

你必須檢查爲indexPath.sectionindexPath.row

if (indexPath.section == 0) { 

    if (indexPath.row) { 

     ... 
    } 

} else if (indexPath.section == 1) 

    if (indexPath.row) { 

     ... 
    } 

} else if ... 
+1

不錯switch語句 – binnyb