2009-10-31 52 views

回答

0

使用一个或两个以下:

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

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 

你有以提供这些方法,并且当该行被选中时将被调用。您需要改变视图才能使其看起来被选中。如果您没有对单元格进行很多更改,则可以使用selectedBackgroundView来突出显示选择内容。

+0

这只适用于修饰,不适用于修饰。查找UITableViewDelegate的Apple文档。 – malaba 2012-04-25 17:56:07

6

的UITableViewCell的有两种方法被调用:

- (void) setHighlighted:(BOOL)highlighted 

- (void) setSelected:(BOOL)selected 

基本上setHighlighted被称为触摸下来(和取消触摸起来),而的setSelected获取通话时,选择“卡”(用户打算按下单元格)。如果您使用正常的表格视图和单元格组合玩耍,您会注意到当您从中滚动时,单元格可能会短暂地突出显示并且不显得高亮。

要突出显示背景,如果您使用自定义背景填充drawRect,您可以更改其颜色并在setHighlighted中调用setNeedsDisplay以使其使用新背景强制重绘。

+0

让我的一天!谢谢。 – Anshu 2012-08-06 13:54:20

0

它不自定义单元格

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

我用了一个UIImageView的自定义单元格内,以动画它的工作。

- (IBAction)highlighteMe 
{ 
    shadowImage.alpha = 0.f; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDuration:0.3]; 
    shadowImage.alpha = 0.3f; 
    [UIView commitAnimations]; 
}