分享

iPhone开发技巧之私有API(2)— UITableView | YIFEIYANG

 wintelsui 2013-12-03

像下面 UITableView 中实现复数选择的设置,需要用到 Undocumented API。


首先,如下所示,在实现了 UITableViewDelegate 的类中实现下面的方法。

1
2
3
4
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 3;
}

其中 UITableViewCellEditingStyle 的定义在 SDK 中如下所示:

1
2
3
4
5
typedef enum {
   UITableViewCellEditingStyleNone,
   UITableViewCellEditingStyleDelete,
   UITableViewCellEditingStyleInsert
} UITableViewCellEditingStyle;

也就是说,我们使用了私有的TableView风格。另外取得被选择的item可以使用 indexPathsForSelectedRows 方法,该方法也也是私有的。

1
- (NSArray *)indexPathsForSelectedRows;

另外,我们也可以使用公开的方法来一个一个的选择/解除cell,而不用使用私有API。

1
2
3
4
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多