以编程方式"闪烁" UITableViewCell将背景颜色设置为白色

时间:2014-04-28 16:30:09

标签: uitableview ios7 uigesturerecognizer

我在UILongPressGestureRecognizer中设置了UICollectionView来调用

- (void)longPress:(UILongPressGestureRecognizer *)gesture {
    if (gesture.state == UIGestureRecognizerStateBegan) {
        CGPoint point = [gesture locationInView:self.collectionView];
        NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:point];
        if (indexPath) {
            self.manager.currentLongPressIndex = indexPath.row;
            [self showPopover];
        }
    }
}

该方法显示的UIPopover有一个UITableView。我的目标是“闪现”(选择然后取消选择UITableViewCell)并滚动显示它。我就是这样做的:

- (void)viewDidLoad {
    [super viewDidLoad];
    // get the current index path
    NSIndexPath *path = [NSIndexPath indexPathForRow:self.manager.currentLongPressIndex inSection:0];
    // set flag
    self.cellIsFlashing = YES;
    // select cell
    [self.tableView selectRowAtIndexPath:path animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.cellIsFlashing == NO) {
        [self.viewController.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
    } else {
        self.cellIsFlashing = NO;
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

这种方法有效,但所选单元格的背景颜色变为白色,闪光效果看起来不太好,看起来根本没有动画效果。

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试推迟取消选择过程:

-(void)deselectRow:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    ... // your code here

    // call the deselect method with 0.3 second delay
    [self performSelector:@selector(deselectRow:) withObject:indexPath afterDelay:0.3f];
}

不确定这是否会起作用但值得一试。

答案 1 :(得分:0)

通过将单元格选择代码从viewDidLoad更改为viewDidAppear:animated:

来解决问题
相关问题