快速向后滑动时,UITableViewCell不会被取消选中 [英] UITableViewCell doesn't get deselected when swiping back quickly

查看:89
本文介绍了快速向后滑动时,UITableViewCell不会被取消选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已将我的三个应用程序更新到iOS 7,但在这三个应用程序中,尽管它们没有共享任何代码,但我遇到的问题是,如果用户滑动返回导航控制器(而不是点击后面)按钮)快速,单元格将保持其选定状态。

I've now updated three of my apps to iOS 7, but in all three, despite them not sharing any code, I have the problem where if the user swipes to go back in the navigation controller (rather than tap the back button) quickly, the cell will remain in its selected state.

对于三个应用程序,一个使用以编程方式创建的自定义单元格,另一个使用在故事板中创建的自定义单元格第三个使用UITableView的一个非常基本的子类中的默认单元格,也在故事板中。在所有三种情况下,细胞不会自行取消选择。如果用户缓慢滑动或点击后退按钮,他们会正常取消选择。

For the three apps, one uses custom cells created programmatically, another uses custom cells created in a storyboard and the third uses default cells in a very basic subclass of UITableView, also in a storyboard. In all three cases, the cells don't deselect by themselves. If the user swipes slowly, or hits the back button, they deselect as normal.

这只发生在我的iOS 7应用程序中,Apple自己的应用程序和升级的第三方应用程序对于iOS 7而言,所有似乎都表现正常(尽管细胞取消选择的速度略有不同)。

This is only happening in my iOS 7 apps, Apple's own apps and third party apps upgraded for iOS 7 all seem to be behaving normally (albeit with slight differences in how quickly the cells gets deselected).

一定有些事情我做错了,但我我不确定是什么?

There must be something I'm doing wrong, but I'm not sure what?

推荐答案

我正在处理同样的问题。 UICatalog

I'm dealing with the same problem right now. The UICatalog-sample from Apple seems to bring the dirty solution.

这真的不会让我开心。如前所述,它使用 [self.tableView deselectRowAtIndexPath:tableSelection animated:NO]; 取消选择当前选定的行。

It really doesn't make me happy at all. As mentioned before it uses [self.tableView deselectRowAtIndexPath:tableSelection animated:NO]; to deselect the currently selected row.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // this UIViewController is about to re-appear, make sure we remove the current selection in our table view
    NSIndexPath *tableSelection = [self.tableView indexPathForSelectedRow];
    [self.tableView deselectRowAtIndexPath:tableSelection animated:NO];

    // some over view controller could have changed our nav bar tint color, so reset it here
    self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor];
}

我不得不提示示例代码可能不是 iOS 7 iOS 8 iOS 9 iOS 10-ready

I have to mention the sample code may not be iOS 7 iOS 8 iOS 9 iOS 10-ready

让我感到困惑的是 UITableViewController类参考


当表格视图第一次加载时即将出现,
table-view controller重新加载表视图的数据。 每次显示表视图时,它还清除其选择的b $ b(有或没有动画,取决于请求)
UITableViewController
类在超类方法 viewWillAppear:中实现。您
可以通过更改
clearsSelectionOnViewWillAppear 属性中的值来禁用此行为。

When the table view is about to appear the first time it’s loaded, the table-view controller reloads the table view’s data. It also clears its selection (with or without animation, depending on the request) every time the table view is displayed. The UITableViewController class implements this in the superclass method viewWillAppear:. You can disable this behavior by changing the value in the clearsSelectionOnViewWillAppear property.

这正是我期望的行为......但它似乎不起作用。既不适合你,也不适合我。我们真的必须使用脏解决方案并自行完成。

This is exactly the behavior I expect… but it does not seem to work. Neither for you nor for me. We really have to use the "dirty" solution and do it on our own.

这篇关于快速向后滑动时,UITableViewCell不会被取消选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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