问题描述
以下是我的单元格的设置:
- (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
或 code>,没有什么发生,因为
backgroundView
和 accessoryView
都似乎为零。
当设置 accessoryType
而不是 accessoryView
,
从:
backgroundView
对于纯样式表(UITableViewStylePlain)中的单元格,缺省值为nil,对于分组样式表UITableViewStyleGrouped,缺省值为nil。 UITableViewCell将背景视图添加为所有其他视图后面的子视图,并使用其当前框架位置。
这些视图将是nil,直到您定义它们,因此您可以根据需要设置其背景。
Here's how my cells are set up:
- (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;
}
As one can see, I set the background of the contentView
, and that works just fine - but when I try to do the same thing with backgroundView
or accessoryView
, nothing happens because backgroundView
and accessoryView
both seem to be nil.
When one sets the accessoryType
rather than the accessoryView
, how does one then go about setting the background of the accessory?
From UITableViewCell Class Reference:
backgroundView
accessoryView
These views will be nil until you define them, and so you can set their backgrounds as desired.
这篇关于UITableViewCell attachmentType set,但是attachmentView为nil。如何设置accessoryView backgroundColor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!