【发布时间】:2013-02-10 09:29:15
【问题描述】:
我有一个带有图像视图和标签的自定义单元格。当用户在表格视图中选择特定单元格时,我想更改其图像和标签字体颜色。我该怎么做?我想避免默认的单元格选择方式(以蓝色突出显示单元格)并使用上述方法代替。
【问题讨论】:
标签: iphone xcode uitableview uiimageview
我有一个带有图像视图和标签的自定义单元格。当用户在表格视图中选择特定单元格时,我想更改其图像和标签字体颜色。我该怎么做?我想避免默认的单元格选择方式(以蓝色突出显示单元格)并使用上述方法代替。
【问题讨论】:
标签: iphone xcode uitableview uiimageview
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCell *selectedCell = (MyCustomCell *)[tableView cellForRowAtIndexPath:indexPath];
//selectedCell.textLabel.textColor = <#your color#>
//selectedCell.myImage = <#your image>
}
如果你想改变选定的单元格背景颜色,试试这个。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellId = @"cellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgColorView];
}
}
【讨论】: