2012-06-25 2 views
-1

У меня есть UITableView для моего MasterView приложения SplitView.Изменить цвет на выбор - TableView/SplitView

При выборе любой строки цвет этой строки становится синим. Я хочу изменить его на черный или темно-серый цвет. Как я могу это сделать?

Спасибо.

ответ

2
-(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]; 
    } 
} 

Или вы можете попробовать это на cellForRowAtIndexPath

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]; 

} 
+0

Что такое таблицаCell ?? Где я должен объявить это? – gamersoul

+0

попробуйте обновленный код .. –

+0

kz .. есть ли какие-либо другие цветовые схемы, кроме синих и серых? как красный или черный? Я попытался использовать строку кода: "cell.selectionStyle = [UIColor colorWithWhite: 0.2 alpha: 1.0];" но он не работает: -/ – gamersoul

2

После перечисления определяется для стиля выбора -

typedef enum { 
    UITableViewCellSelectionStyleNone, 
    UITableViewCellSelectionStyleBlue, 
    UITableViewCellSelectionStyleGray 
} UITableViewCellSelectionStyle; 

Так что для вашей цели вы можете использовать - UITableViewCellSelectionStyleGray

0

Вы можете изменить цвет выбранной ячейки следующим образом:

- (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 - это 2px-изображение вашего цвета.

Смежные вопросы