如何为 UITableView 索引事件添加操作 - 对于每个字母

Posted

技术标签:

【中文标题】如何为 UITableView 索引事件添加操作 - 对于每个字母【英文标题】:How to add action for UITableView index event - for each alphabet letter 【发布时间】:2011-04-26 07:37:58 【问题描述】:

我有字母条(索引),就像在 Apple 的通讯录应用中一样,显示在 UITableView 中,但现在我想在我触摸它们时为每个字母添加一个动作?

【问题讨论】:

【参考方案1】:

看看UITableViewDataSource协议。

你会很容易知道是哪个字母被触摸了。

【讨论】:

【参考方案2】:

利用 tableView 是一个滚动视图这一事实,并且您的 <UITableViewDelegate> 也将符合 <UIScrollViewDelegate> 并使用 -scrollViewDidScroll: 方法:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
    if(![scrollView isDragging] && ![scrollView isDecelerating]) 
        NSLog(@"User scrolled using tableView index");
    

最好的,

【讨论】:

以上是关于如何为 UITableView 索引事件添加操作 - 对于每个字母的主要内容,如果未能解决你的问题,请参考以下文章