WWDC笔记:2011 Session 125 UITableView Changes, Tips and Tricks

What’s New

Automatic Dimensions

- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section
CGFloat UITableViewAutomaticDimension

 Automatic Animation Style

UITableViewRowAnimationAutomatic

 New Update Methods

- (void)moveSection:(NSInteger)section
          toSection:(NSInteger)newSection
- (void)insertSections:(NSIndexSet *)sections
      withRowAnimation:(UITableViewRowAnimation)animation
- (void)deleteSections:(NSIndexSet *)sections
      withRowAnimation:(UITableViewRowAnimation)animation
- (void)reloadSections:(NSIndexSet *)sections
      withRowAnimation:(UITableViewRowAnimation)animation

Demo

[self.tableView beginUpdates];

//更新cell位置section位置等等

[self.tableView endUpdates];

Menu Suppor

- (BOOL)tableView:(UITableView *)tableView
        shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
- (BOOL)tableView:(UITableView *)tableView
 canPerformAction:(SEL)action
forRowAtIndexPath:(NSIndexPath *)indexPath
       withSender:(id)sender
- (void)tableView:(UITableView *)tableView
    performAction:(SEL)action
forRowAtIndexPath:(NSIndexPath *)indexPath
       withSender:(id)sender

Multiple Selection

Table View Properties

BOOL allowsMultipleSelection
BOOL allowsMultipleSelectionDuringEditing
BOOL allowsSelection
BOOL allowsSelectionDuringEditing

Table View Method

- (NSArray *)indexPathsForSelectedRows
- (NSIndexPath *)indexPathForSelectedRow

Table View Cell Property

UIView *multipleSelectionBackgroundView
UIView *selectedBackgroundView

Automatic Cell Loading

- (void)registerNib:(UINib *)nib
        forCellReuseIdentifier:(NSString *)identifier

 Nib Constraints

  • Nib must contain a single table view cell
  • Cell’s reuse identifier must match the one specified above (or be nil)

Tips and Tricks

Action Row

Floating View

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

 Dynamic Background View

 两倍background大小,animation option: UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear

Related Session

  • Simplifying Touch Event Handling with Gesture Recognizers
  • Advanced Gesture Recognition
原文地址:https://www.cnblogs.com/wxy325/p/3190249.html