Iphone 更改所选内容的颜色-TableView/SplitView

Iphone 更改所选内容的颜色-TableView/SplitView,iphone,objective-c,ios,xcode,ipad,Iphone,Objective C,Ios,Xcode,Ipad,我有一个用于SplitView应用程序主视图的UITableView 选择任何行时,该行的颜色将变为蓝色。我想把它换成黑色或深灰色。我该怎么做 谢谢 -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *

我有一个用于SplitView应用程序主视图的
UITableView

选择任何行时,该行的颜色将变为蓝色。我想把它换成黑色或深灰色。我该怎么做

谢谢

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *tableCell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (tableCell == nil) {
    tableCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease] ;   

[tableCell setSelectionStyle:UITableViewCellSelectionStyleGray]; 
   }
 }
或者您也可以在
cellforrowatinexpath

if (indexPath.row == selectedIndex) 
{ 
    Cell.LblDynamicCell.textColor=[UIColor whiteColor];
    Cell.LblBackView.backgroundColor=[UIColor Black];
}
//LblDynamicCell,LblBackView objects  declare in cellViewController class

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
  selectedIndex = indexPath.row;
  [self.ResultTbl reloadData];

 }

为选择样式定义了以下枚举-

typedef enum {
    UITableViewCellSelectionStyleNone,
    UITableViewCellSelectionStyleBlue,
    UITableViewCellSelectionStyleGray
} UITableViewCellSelectionStyle;

因此,您可以使用-
UITableViewCellSelectionStyleGray

更改所选单元格的颜色,如下所示:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated

    {
        [super setSelected:selected animated:animated];

        UIImageView *theImageView = [[UIImageView alloc] initWithImage:[UIImage imageName:@"table_selected_cell.png"]];
        self.selectedBackgroundView = theImageView;
        [theImageView release];
    }

要更改您选择的颜色,其中table_selected_cell.png是您颜色的2倍图像。

什么是tableCell??我应该在哪里申报呢。。除了蓝色和灰色,还有其他颜色吗??喜欢红色还是黑色??我试着使用代码行:“cell.selectionStyle=[uicolorWithWhite:0.2 alpha:1.0];”但它似乎不起作用:-/@gamersoul在我看来,你似乎在试图做一些你力所能及的事情。放松,将项目暂停几周,学习更多有关编程的基本知识,然后重试。为了使用蓝色或灰色以外的样式,您必须实现UITableViewCell的“selectedBackgroundView”属性,并从头开始绘制所需的外观。