B.S*_*.S. 129 cocoa-touch objective-c uitableview uikit ios
我UITableView只有在iOS 7中有一些奇怪的问题.
UITableViewCellSeparator消失在第一行上方和最后一行下方.有时在选择行或某些滚动操作后会出现.
在我的情况下tableView是从Storyboard带UITableViewStylePlain样式加载.问题肯定不在UITableViewCellSeparatorStyle,默认情况下没有改变UITableViewCellSeparatorStyleSingleLine.
正如我在Apple Dev论坛上所读到的(这里和这里),其他人有这样的问题,并找到了一些解决方法,例如:
Workaround: disable the default selection and recreate the behaviour in a method
trigged by a tapGestureRecognizer.
Run Code Online (Sandbox Code Playgroud)
但我仍在寻找这种分隔符奇怪行为的原因.
有任何想法吗?
更新:正如我在XCode 5.1 DP和iOS 7.1 beta中看到的那样,Apple试图解决这个问题.现在,在一些刷新之后,有时需要在最后一行的下方显示分隔符,但不是在创建tableview之后.
Ort*_*ntz 77
我抛弃了受影响的单元格的子视图层次结构,发现它_UITableViewCellSeparatorView被设置为隐藏.难怪它没有显示!
我layoutSubviews在我的UITableViewCell子类中重写,现在分隔符可靠地显示:
Objective-C:
- (void)layoutSubviews {
[super layoutSubviews];
for (UIView *subview in self.contentView.superview.subviews) {
if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
subview.hidden = NO;
}
}
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特:
override func layoutSubviews() {
super.layoutSubviews()
guard let superview = contentView.superview else {
return
}
for subview in superview.subviews {
if String(subview.dynamicType).hasSuffix("SeparatorView") {
subview.hidden = false
}
}
}
Run Code Online (Sandbox Code Playgroud)
这里提出的其他解决方案对我来说并不一致,或者看起来很笨重(添加自定义1 px页脚视图).
sam*_*tte 42
这对我有用:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// fix for separators bug in iOS 7
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
Run Code Online (Sandbox Code Playgroud)
小智 12
我还与缺少分离的问题,我发现,当问题发生仅heightForRowAtIndexPath是返回一个十进制数.解:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return ceil(yourHeight) // Ceiling this value fixes disappearing separators
}
Run Code Online (Sandbox Code Playgroud)
air*_*ulg 11
您是否尝试在标题和表格的页脚中添加高度为1的UIView,并带有浅灰色背景色?基本上它会模拟第一个和最后一个分隔符.
小智 8
@samvermette
我通过使用此委托方法修复了问题.现在它没有闪烁:
-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
// fix for separators bug in iOS 7
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}
-(void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
// fix for separators bug in iOS 7
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}
Run Code Online (Sandbox Code Playgroud)
我们在应用中遇到了这个问题.当用户选择一个单元格时,新的表格视图被推送到导航控制器堆栈上,然后当用户将其弹出时,分隔符丢失.我们通过把解决它[self.tableView deselectRowAtIndexPath:indexPath animated:NO];在didSelectRowAtIndexPath表视图委托方法.
如果您需要一个更容易(虽然有点凌乱)的解决方法,尝试在重新加载数据并完成默认动画后选择和取消选择单元格.
只需添加:
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
Run Code Online (Sandbox Code Playgroud)
我发现最简单的解决方案是,在重新加载单元格后,还重新加载上面的单元格:
if (indexPath.row > 0) {
NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row - 1 inSection:indexPath.section];
[self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationNone];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
47929 次 |
| 最近记录: |