【问题标题】:IOS7 Table view cell touching delay with cell property UITableViewCellSelectionStyleNoneIOS7表格视图单元格触摸延迟与单元格属性UITableViewCellSelectionStyleNone
【发布时间】:2014-06-01 05:22:13
【问题描述】:

我想制作一个像这样的自定义表格视图单元格。

  • 如果cell.selectionStyle = UITableViewCellSelectionStyleDefault,触摸时没有延迟,但我的标题标签的背景颜色消失了。

  • 如果cell.selectionStyle = UITableViewCellSelectionStyleNone,标题标签的背景颜色很好,但是显示模态VC有感人的延迟。提前致谢!

【问题讨论】:

  • 什么是“触摸延迟”?该属性纯粹是装饰性的,不会改变细胞的行为。
  • @Dima 模态VC出现在前面的时间真的很长,当单元格被触摸时。

标签: ios objective-c ios7 uitableview custom-cell


【解决方案1】:

你可以在UITableViewDelegate方法下实现类似的东西

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

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    switch (cell.selectionStyle) {

        case UITableViewCellSelectionStyleNone:

            // your are making an delay with NSTimer
            [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(trigger:) userInfo:cell repeats:NO];
            break;

        case UITableViewCellSelectionStyleDefault:

            // changing your labels color
            [cell.textLabel setBackgroundColor:[UIColor whiteColor]];
            break;

        default:
            break;
    }

}

- (void)trigger:(id)timer {

    UITableViewCell *cell = (UITableViewCell *)[timer userInfo];

    // _yourModelController is your destination controller
    [self presentViewController:_yourModelController animated:YES completion:NULL];
}

但我个人不建议根据selectionStyle 属性做出决策。

【讨论】:

  • 谢谢!这很有帮助! :)
  • @user3627556 如果它有帮助并且如果您认为答案是正确的,那么不要忘记将其标记为对其他用户有帮助的正确答案。
  • 我使用 UIGraphicsGetImageFromCurrentImageContext() 函数将 UIImage 作为标签的背景视图,它可以工作。我用谷歌搜索了一些关于 IOS7 tableViewCell 继承的信息,有一个名为 UITableViewCellScrollView 父单元格的 contentView 的新视图。我认为这与问题有关。还是谢谢你,但我认为这不是最好的答案。对不起!
猜你喜欢
  • 1970-01-01
  • 2020-01-01
  • 2012-07-20
  • 1970-01-01
  • 1970-01-01
  • 2012-01-16
  • 1970-01-01
  • 2012-01-10
  • 1970-01-01
相关资源
最近更新 更多