[英]UITableView Change the cell style
我有2個表視圖我想根據第一個表視圖中選定的行自定義第二個視圖的單元格樣式。 它在定制配件時起作用但不適合風格。 我使用iOS 7.1和Xcode 5.1作為我使用以下代碼
提前致謝
- (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;
}
如果不創建新單元格,則無法更改單元格的樣式。
這條線:
cell.selectionStyle = UITableViewCellStyleValue1;
沒有意義。 您試圖通過傳入單元格樣式的枚舉值來更改單元格的選擇樣式。 這是兩個不同的概念。
當您想要更新單元格的樣式(而不是選擇樣式)時,需要調用UITableView initWithStyle:reuseIdentifier:
再次傳遞所需的樣式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.