我在「UITableViewCell」中使用自定義圖像作爲複選標記 - '[email protected]',但它顯示在單元格中的任何位置。任何人都可以建議如何使其僅顯示單個選定的單元格?所選行的自定義複選標記
這裏是我的代碼:實現你試圖做的是使用一個按鈕,設置背景圖片爲您的複選框
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,10, 300, 30)];
[cell.contentView addSubview:label];
label.text = [tableArr objectAtIndex:indexPath.row];
label.font = [UIFont fontWithName:@"Whitney-Light" size:20.0];
label.tag = 1;
UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"[email protected]"]];
cell.accessoryView = checkmark;
return cell;
}
你有一個屏幕截圖。我以幾乎相同的方式做了幾次。只需使用圖像創建UIImageView並將其分配給cell.accessoryView即可。你檢查了cell.accessoryView的框架嗎?它是什麼? –
@CodeMonkey請在將來進行更完整的修改,修復帖子中的多個問題。此外,僅將「代碼塊」用於「代碼」。 – Undo
當然可以。謝謝撤消。 –