我想制作一个像这样的自定义表格视图。
如果cell.selectionStyle = UITableViewCellSelectionStyleDefault
,触摸时没有延迟,但我的标题标签的背景颜色消失了。
如果cell.selectionStyle = UITableViewCellSelectionStyleNone
,标题标签的背景颜色很好,但是提示模式VC有触摸延迟。提前致谢!
答案 0 :(得分:0)
您可以在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
属性做出决策。