您的位置:首页 > 产品设计 > UI/UE

iPhone开发技巧之私有API(2)--- UITableView

2011-05-17 21:41 381 查看
像下面 UITableView 中实现复数选择的设置,需要用到 Undocumented API。





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

1
2
3
4

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

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

1
2
3
45

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;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: