我正在做一个项目,我必须预先选择一个特定的单元格。
我可以使用-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];
}
你能帮上忙吗?
发布于 2010-10-19 20:04:20
使用此代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Change the selected background view of the cell.
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Swift 3.0:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//Change the selected background view of the cell.
tableView.deselectRow(at: indexPath, animated: true)
}
发布于 2012-05-24 05:18:51
在表视图委托的didSelectRowAtIndexpath
中(或从任何位置)使用以下方法
[myTable deselectRowAtIndexPath:[myTable indexPathForSelectedRow] animated:YES];
发布于 2013-02-28 02:53:34
试试这个:
for (NSIndexPath *indexPath in tableView.indexPathsForSelectedRows) {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
https://stackoverflow.com/questions/3968037
复制相似问题