使用 UITableViewStyleGrouped 建立表格視圖時,預設會顯示圓角分組外觀。若需呈現直角矩形列表(類似 Plain 樣式但保留分區功能),需自訂單元格背景。
在 tableView:cellForRowAtIndexPath: 代理方法中,將單元格的 backgroundView 設為空白視圖:
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
此舉會移除系統預設的圓角背景,使單元格呈現直角矩形。若需進一步美化,可在 backgroundView 中加入自訂圖片或漸層色塊。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// 關鍵:移除預設圓角背景
cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
}
cell.textLabel.text = [self dataForRowAtIndexPath:indexPath];
return cell;
}
sectionHeaderView 或 sectionFooterView 的顯示。separatorStyle 不為 UITableViewCellSeparatorStyleNone。