UI基础—UITableView

来源:互联网 发布:excel不规则数据分列 编辑:程序博客网 时间:2024/05/29 13:30

UITavleView Summary

本文对UITableView头文件中的属性和方法做了简单总结,对于那些基本的常用的属性和方法,本文并没有详述,因为它们是使用UITableView的基础,这里仅仅是在此基础上的拓展。
[toc]

1 Importace

1.1 RowEditing(Delegate Methods)

  • property editing == YES 缺省是NO, 所以要编辑必须开启。

  • - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
    是数据源方法,默认是Yes,为保证数据的安全,在数据层给特定的数据设置权限,在加载的时候调用。进行插入和删除操作时,会调用,而且会调用canMove方法(因为其造成了Cell的移动)。在剪贴和黏贴的时候也会调用该方法,而且剪切也会调用canMove方法。

  • BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
    该方法是数据源方法,默认是yes。也是数据源层的安全设置。在加载的时候会调用,当出现cell的 移动时,会调用。但是对于真正的Move操作,其仅仅调用Move的操作方法,而不会调用该方法,即前者默认包含该方法。

  • ??Edit操作是,canEdit方法会被多次调用,次数和Cell的个数不同,而canMove则仅仅调用一次。

1.1.1 Insert and Delete

  • (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indeYesath;

  • (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

  • (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0);

  • (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;

  • (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;

1.1.2 Copy Cut Paste

  • (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(5_0);

  • (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender NS_AVAILABLE_IOS(5_0);

  • (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender NS_AVAILABLE_IOS(5_0);

1.1.3 Move

  • (void)moveRowAtIndexPath:(NSIndexPath )indexPath toIndexPath:(NSIndexPath )newIndexPath
    Move 操作的实现方法,不实现canMove方法的话,该方法也可以实现Move,如果canMove然后no的话,则该方法也无效。在进行Move操作的时候,canMove并不被调用,仅仅调用该方法。

1.2 RowEditing:Insert、Delete、 Move、and Reload specific row (Own methods)

  • (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;

  • (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;

  • (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);

  • (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection NS_AVAILABLE_IOS(5_0);

  • (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

  • (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

  • (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);

  • (void)moveRowAtIndexPath:(NSIndexPath )indexPath toIndexPath:(NSIndexPath )newIndexPath
    使用注意:insert and delete 方法都要首先对数据源进行对应的处理,然后再调用对象方法,否则无法运行。而Move操作,可以在不对数据源进行对应处理的情况下直接调用,但是数据源并没有改变。
    上面的描述,仅仅在row related 方面进行了验证,section related 没有进行实例验证(应该是同样的道理)

当将上面的方法放在- (void)beginUpdates 方法中使用时,涉及到调用的顺序,还没有弄明白??

1.3 own methods about reusing

  • (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.

  • (id)dequeueReusableCellWithIdentifier:(NSString )identifier forIndexPath:(NSIndexPath )indexPath NS_AVAILABLE_IOS(6_0); // newer dequeue method guarantees a cell is returned and resized properly, assuming identifier is registered

  • (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier

1.4 Other Editing

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"action" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {    }];    return @[rowAction];}

自定义滑动Cell的action按钮和事件。

1.5 Other

  1. Const UITableViewRowAnimation 可以设置Cell的自使用高度,以及footer 和 header的自适应高度(没试过)其中前者需要和estimatedRowHeight配合使用,后者应该也是,其也有对应的estimated sh属性。
  2. Const UITableViewIndexSearch 放在索引标题数组的首位,为索引标题添加放大镜图标。
  3. NSString *const UITableViewSelectionDidChangeNotification; 选择改变的通知。
  4. 要想得到tableview的背景色,需要将Cell的背景色清除。
  5. 得到indexpath的自身方法:

    • (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
    • (NSIndexPath )indexPathForCell:(UITableViewCell )cell;
    • (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
  6. 可见Cells:

    • (NSArray *)visibleCells;
    • (NSArray *)indexPathsForVisibleRows;
  7. 多操作组合:

    • (void)beginUpdates; // allow multiple insert/delete of rows and sections to be animated simultaneously. Nestable
    • (void)endUpdates;

2 Question

  1. 继承自NSObject的类UITableViewRowAction 如何使用,什么作用。
  2. 从nib和class 实现Cell和header的重用:

    • (void)registerNib:(UINib )nib forCellReuseIdentifier:(NSString )identifier NS_AVAILABLE_IOS(5_0);
    • (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

    • (void)registerNib:(UINib )nib forHeaderFooterViewReuseIdentifier:(NSString )identifier NS_AVAILABLE_IOS(6_0);

    • (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
0 0
原创粉丝点击