我正在做一个项目,我必须预先选择一个特定的单元格。
我可以使用 -willDisplayCell
预先选择一个单元格,但是当用户单击任何其他单元格时我无法取消选择它。
- (void)tableView:(UITableView*)tableView
willDisplayCell:(UITableViewCell*)cell
forRowAtIndexPath:(NSIndexPath*)indexPath
{
AppDelegate_iPad *appDelegte =
(AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
if ([appDelegte.indexPathDelegate row] == [indexPath row])
{
[cell setSelected:YES];
}
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AppDelegate_iPad *appDelegte =
(AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
NSIndexPath *indexpath1 = appDelegte.indexPathDelegate;
appDelegte.indexPathDelegate = indexPath;
[materialTable deselectRowAtIndexPath:indexpath1 animated:NO];
}
你能帮忙吗?
最佳答案
使用此代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Change the selected background view of the cell.
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//Change the selected background view of the cell.
tableView.deselectRow(at: indexPath, animated: true)
}
https://stackoverflow.com/questions/3968037/
相关文章:
objective-c - Swift 编译器错误 : "non-modular header in
ios - NSUserDefaults - 如何判断 key 是否存在
objective-c - 为什么 Objective-C 文件使用 .m 扩展名?
objective-c - 如何在标题更改时停止不需要的 UIButton 动画?
objective-c - 如何在 Objective-C 中声明类级别的属性?
ios - 如何在我的 iOS 应用程序中每 n 分钟更新一次后台位置?
ios - 内部测试时 ITSAppUsesNonExemptEncryption 导出合规性?