[英]UITableViewCellAccessoryCheckmark covers cell separator on iOS 7
在 iOS 7 上使用此代碼會導致分隔符視圖被覆蓋或縮短:
cell.accessoryType = UITableViewCellAccessoryCheckmark;
如何修復分隔符視圖?
我正在使用原型單元,但我沒有對它們進行子類化。
[編輯]
這是來自 cellForRowAtIndexPath 的相關代碼:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
if (indexPath.section == kDefaultViewSection){
NSArray *defaultViewNames = @[LQSettingsSentenceView, LQSettingsFullTextView, LQSettingsFlashcardsView];
NSString *preferredViewName = [LQSettings valueForKey:LQSettingsPreferredLessonView];
if ([defaultViewNames[indexPath.row] isEqualToString:preferredViewName]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section != kDefaultViewSection){
return;
}
// Just turn all checks off for a minute
for (int x=0; x<3; x++) {
NSIndexPath *ip = [NSIndexPath indexPathForRow:x inSection:kDefaultViewSection];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:ip];
cell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
在表格視圖中禁用分隔符並在單元格底部添加子視圖自定義分隔符視圖。
您可以在 UITableViewCell 的backgroundView
屬性上設置backgroundView
。 在該自定義 backgroundView 中添加一個分隔線視圖,擴展視圖的整個寬度。 backgroundView 不受附件視圖的影響。
打開 var backgroundView: UIView?
UITableViewStylePlain 中的單元格默認為 nil,UITableViewStyleGrouped 中的默認值為非 nil。 'backgroundView' 將被添加為所有其他視圖后面的子視圖。
例如...
let separator = UIView()
separator.backgroundColor = .gray
let customBackgroundView = UIView()
customBackgroundView.addSubview(separator)
separator.translatesAutoresizingMaskIntoConstraints = false
separator.bottomAnchor.constraint(equalTo: customBackgroundView.bottomAnchor).isActive = true
separator.widthAnchor.constraint(equalTo: customBackgroundView.widthAnchor).isActive = true
separator.heightAnchor.constraint(equalToConstant: 1).isActive = true
backgroundView = customBackgroundView
沒有一個答案有幫助。 我結束了:
在cellforrow函數中,
if selectedItem == tableData[indexPath.tow]{ cell.checkMarkLabel.isHidden = false } else { cell.checkMarkLabel.isHidden = true }
在didSelectRow函數中,
selectedItem = tableData[indexPath.tow] DispatchQueue.main.async { self.tableView.reloadRows(at: tableView.indexPathsForVisibleRows!, with: .none) }
轉到 Xib 或 Storyboard,選擇 tableview 並將分隔符樣式設置為單行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.