UITableViewController 选择部分的标题 [英] UITableViewController select header for section

查看:11
本文介绍了UITableViewController 选择部分的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个部分的 UITableView.每个部分都有一个部分标题(自定义视图)是否有一种简单的方法可以检测何时有人选择了部分标题?(就像 didSelectRowAtIndexPath,但是对于标题?)

I have a UITableView with multiple sections. Each section has a section header (a custom view) is there an easy way to detect when someone selects the section header? (Just like didSelectRowAtIndexPath, but for the header?)

推荐答案

不,没有办法用 UITableViewDelegate 做到这一点.

No there is no way to do it with the UITableViewDelegate.

您可以做的是添加一个与节标题视图大小相同的按钮并将其添加到视图中.将按钮的标签设置为节索引.然后只需将 UIViewController 添加为 UIControlEventTouchUpInside 的目标.

What you can do is to add a button the size of the section header view and add it to the view. Set the tag of the button to the section index. Then just add the UIViewController as a target for the UIControlEventTouchUpInside.

然后通过查看按钮的标签可以看到点击了哪个部分.

Then by looking at the tag of the button you can see which section is clicked.

这篇关于UITableViewController 选择部分的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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