2011-08-08 76 views
1

当我点击任何单元格文本时,它变成蓝色,当我再次回来时,它仍然是蓝色,直到我点击另一个单元格如何解决此问题 我使用UITableView与详细文本标签。UITableView单元格颜色不消失

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell1.png"]]; 
    [cell setBackgroundView:img]; 
    [img release]; 
} 

回答

2

将此代码添加到您的类:

- (void)viewWillAppear:(BOOL)animated 
{ 
    // this UIViewController is about to re-appear, make sure we remove the current selection in our table view 
    NSIndexPath *tableSelection = [self.tableView indexPathForSelectedRow]; 
    [self.tableView deselectRowAtIndexPath:tableSelection animated:NO]; 
} 
5

取消你的行委托的didSelectRowAtIndexPath:方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    ... 
} 
+0

- (空)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath { \t \t CategoriesList * dvController = [[CategoriesList alloc] initWithNibName:@“CategoriesList”bundle:nil]; \t //将选定的对象传递给新的视图控制器。 \t //dvController.description = description; \t //dvController.title=title; \t //dvController.descriptionImage=descriptionImage; \t [self.navigationController pushViewController:dvController animated:YES]; \t [dvController release]; \t } – ali

+0

我在编辑你的代码,但它不工作 – ali

+0

@ali“不工作”是一个不好的描述。什么不工作? – Vladimir

0

当用户选择的行

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
    .. your view changing code 
} 
+0

我这样做,它的工作正常与一个控制器,但在第二个视图中,当我去那里,并回复按钮移动表视图它给出异常 – ali

0

你需要做的只是删除选择样式如下:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

并添加

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 

cellForRowAtIndex