为什么没有调用 -didDeselectRowAtIndexPath? [英] Why is -didDeselectRowAtIndexPath not being called?

查看:30
本文介绍了为什么没有调用 -didDeselectRowAtIndexPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新项目(Xcode 4,Master-Detail 应用程序)只是为了看看我是否做错了什么,但我仍然遇到同样的问题.当用户取消选择一个单元格时,我想调用 -reloadData,所以这是我的代码:

I created a fresh project (Xcode 4, Master-Detail application) just to see if I'm doing something wrong, but I still have the same problem. I want to call -reloadData when the user deselects a cell, so this is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    [tableView reloadData];
}

-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    return indexPath;
}

问题是 didDeselectRowAtIndexPathwillDeselectRowAtIndexPath 似乎没有被调用.这是预期的行为吗?tableView:didDeselectRowAtIndexPath: state

The problem is that didDeselectRowAtIndexPath and willDeselectRowAtIndexPath don't seem to be called. Is this the expected behavior? The docs for tableView:didDeselectRowAtIndexPath: state

告诉委托指定的行现在已取消选择.

Tells the delegate that the specified row is now deselected.

所以我想它应该像我想的那样工作.

so I guess that it should work as I thought.

推荐答案

tableView:willDeselectRowAtIndexPath: 也说

此方法仅在存在选择时调用用户尝试选择不同的行.委托发送此方法对于先前选择的行.您可以使用UITableViewCellSelectionStyleNone 禁用单元格突出显示.

This method is only called if there is an existing selection when the user tries to select a different row. The delegate is sent this method for the previously selected row. You can use UITableViewCellSelectionStyleNone to disable the appearance of the cell highlight on touch-down.

当我使用 UITableViewCellSelectionStyleNone 时,它对我们不起作用.

It not worked for we when I used UITableViewCellSelectionStyleNone.

这篇关于为什么没有调用 -didDeselectRowAtIndexPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆