当表重新出现时,UITableView不会自动取消选择所选行 [英] UITableView does not automatically deselect the selected row when the table re-appears

查看:106
本文介绍了当表重新出现时,UITableView不会自动取消选择所选行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户从详细信息视图中弹回时,通常会在动画中取消选择 UITableView 中的选定行。

Normally a selected row in a UITableView gets deselected with an animation when the user pops back from the detail view.

但是,在我的情况下,我在 UIViewController中嵌入了 UITableView 我必须在 viewWillAppear 中手动执行此操作:

However, in my case where I have a UITableView embedded in a UIViewController I have to do it manually in viewWillAppear like so:

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    // For some reason the tableview does not do it automatically
    [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow 
                                  animated:YES];  
}

为什么会这样以及如何解决?

Why is this and how to fix it?

推荐答案

当您的主ViewController来自 UITableViewController ,它有属性 clearsSelectionOnViewWillAppear ,默认为 - 所以它会自动清除选择。

When your main ViewController is from type UITableViewController, it has a property clearsSelectionOnViewWillAppear, which is per default YES - so it will clear the selection automatically.

此属性不适用于 UITableView ,我想这是因为它没有 ViewWillAppear 方法。

This property is not available for an UITableView, i guess it's because it has no ViewWillAppear method either.

A UIViewController 不需要这个属性,因为它最初没有 UITableView

A UIViewController doesn't need this property because it has no UITableView originally.

结论:当你不使用 UITableViewController 时,你必须自己实现。

conclusion: you'll have to implement it by yourself when you do not use a UITableViewController.

这篇关于当表重新出现时,UITableView不会自动取消选择所选行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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