2014-02-06 94 views
0

我有2個表格視圖我想根據第一個表格視圖中的選定行自定義第二個視圖的單元格樣式。它可以在定製配件時起作用,但不適用於款式。是因爲我用下面的代碼UITableView更改單元格樣式

在此先感謝

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *TableIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifier]; 
    } 

    cell.detailTextLabel.textColor = [UIColor lightGrayColor]; 
    cell.textLabel.text = [array objectAtIndex:indexPath.row]; 

    if ([selectedRow isEqualToString:@"Cars"]) { 
     [cell setAccessoryType: UITableViewCellAccessoryDetailButton]; 

    } 
    if ([selectedRow isEqualToString:@"Houses"]) { 
     NSArray *temp = [[dic objectForKey:selectedRow]valueForKey:@"Job"]; 

     cell.selectionStyle = UITableViewCellStyleSubtitle; 
     cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; 
     cell.detailTextLabel.text = [temp objectAtIndex:indexPath.row];    
    } 
    if ([selectedRow isEqualToString:@"Libraries"]) { 
     cell.selectionStyle = UITableViewCellStyleValue1; 
    } 

    return cell; 
} 

回答

2

,而無需創建一個新的細胞不能更改單元格的樣式使用的是iOS 7.1和5.1的Xcode 。

行:

cell.selectionStyle = UITableViewCellStyleValue1; 

是沒有意義的。您正試圖通過傳遞單元格樣式的枚舉值來更改單元格的選擇樣式。這是兩個不同的概念。

當您想更新單元格的樣式(而不是選擇樣式)時,需要再次調用UITableView initWithStyle:reuseIdentifier:以傳遞所需的樣式。