YIFEIYANG 易飞扬的博客

1六/100

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

  • 博主:易飞扬
  • 原文链接 : http://www.yifeiyang.net/iphone-development-skills-of-the-private-api-2-uitableview/
  • 转载请保留上面文字。




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

    像下面 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)

    还没有评论.


    发表评论


    还没有引用.