如何在不触摸屏幕的情况下选择单元格?

时间:2011-07-07 13:55:19

标签: objective-c ios uitableview

我有一个UITableViewController,并希望每次加速度计的X轴大于0.5时向下移动我的表中的单元格(当发生此事件时,我增加一个名为“TEST”的值)。如何更改其indexPath.row等于TEST的单元格的背景?

以下是我尝试访问该方法的方法(来自加速计功能),但它给了我一个错误:

  - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration 
{


              if(acceleration.x>0.5)
                TEST++; 
            if(TEST<0) TEST=0;
            if(TEST>19) TEST=19;

             NSIndexPath *temp = [[NSIndexPath alloc] initWithIndex:TEST];
            [self tableView:[self tableView] didSelectRowAtIndexPath:temp];


    }

     I have 20 rows in my table (hence the clamp).

2 个答案:

答案 0 :(得分:1)

scrollToRowAtIndexPath:atScrollPosition:animated:怎么样?

答案 1 :(得分:1)

selectRowAtIndexPath:动画:的scrollPosition:

选择由索引路径标识的接收器中的行,可选择将行滚动到接收器中的某个位置。

  • (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition

参数

indexPath

标识接收器中行的索引路径。

动画 如果您想为选择和位置的任何变化设置动画,则为“是”,如果要立即进行更改,则为“否”。

的scrollPosition

一个常量,用于标识滚动结束时行的接收表视图(顶部,中间,底部)中的相对位置。请参阅“表格视图滚动位置”

这里

            NSIndexPath *temp = [[NSIndexPath alloc] initWithIndex:TEST];


       [self.tableview selectRowAtIndexPath:temp animated:YES scrollPosition:UITableViewScrollPositionNone];