gpt4 book ai didi

iphone - UITableViewCell accessoryType 已设置,但 accessoryView 为 nil。如何设置 accessoryView backgroundColor?

转载 作者:可可西里 更新时间:2023-11-01 03:29:49 25 4
gpt4 key购买 nike

我的单元格是这样设置的:

- (UITableViewCell *)tableView:(UITableView *)tableViewIn cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"subcategory";
UITableViewCell *cell = [tableViewIn dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [[subcategories objectAtIndex:indexPath.row] title];
cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
cell.textLabel.font = [UIFont boldSystemFontOfSize:16];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;

cell.contentView.backgroundColor = [UIColor clearColor];

cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.highlightedTextColor = [UIColor whiteColor];

return cell;
}

如您所见,我设置了 contentView 的背景,效果很好 - 但是当我尝试对 backgroundView 做同样的事情时>accessoryView,没有任何反应,因为backgroundViewaccessoryView 似乎都是nil。

当设置accessoryType 而不是accessoryView 时,如何设置配件的背景?

最佳答案

来自 UITableViewCell Class Reference :

背景 View

Discussion

The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for grouped-style tables UITableViewStyleGrouped). UITableViewCell adds the background view as a subview behind all other views and uses its current frame location.

附件 View

Discussion

If the value of this property is not nil, the UITableViewCell class uses the given view for the accessory view in the table view’s normal (default) state; it ignores the value of the accessoryType property. The provided accessory view can be a framework-provided control or label or a custom view. The accessory view appears in the the right side of the cell.

在您定义它们之前,这些 View 将为零,因此您可以根据需要设置它们的背景。

关于iphone - UITableViewCell accessoryType 已设置,但 accessoryView 为 nil。如何设置 accessoryView backgroundColor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3714676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com