UIKit 框架之UITableView一

UITableView在開發中是用的最多的控件,它包含兩個代理:UITableViewDataSource,UITableViewDelegate,先熟悉下APIios

1.初始化數組

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style; 

 2.UITableViewStyleide

typedef NS_ENUM(NSInteger, UITableViewStyle) {
        UITableViewStylePlain,                  // 平鋪樣式
        UITableViewStyleGrouped                 // 分組樣式
    };

 3.style屬性動畫

@property (nonatomic, readonly) UITableViewStyle           style;

 4.代理atom

@property (nonatomic, assign)   id <UITableViewDataSource> dataSource;
@property (nonatomic, assign)   id <UITableViewDelegate>   delegate;

 5.設置Height代理

//未設置Height時用下面默認
    @property (nonatomic)          CGFloat                     rowHeight;
    @property (nonatomic)          CGFloat                     sectionHeaderHeight;
    @property (nonatomic)          CGFloat                     sectionFooterHeight;
    //默認爲0 nil時表示無預估Height
    @property (nonatomic)          CGFloat                     estimatedRowHeight NS_AVAILABLE_IOS(7_0);
    @property (nonatomic)          CGFloat                     estimatedSectionHeaderHeight NS_AVAILABLE_IOS(7_0);
    @property (nonatomic)          CGFloat                     estimatedSectionFooterHeight NS_AVAILABLE_IOS(7_0);

 6.背景視圖 自動改變Size適應TableView的尺寸, 作爲TableView的子視圖放在最底部rest

@property(nonatomic, readwrite, retain) UIView *backgroundView NS_AVAILABLE_IOS(3_2); 

 7.刷新數據blog

- (void)reloadData; //刷新數據
- (void)reloadSectionIndexTitles NS_AVAILABLE_IOS(3_0);//分組時刷新組索引

 8.節數行數索引

 - (NSInteger)numberOfSections; //節數量
 - (NSInteger)numberOfRowsInSection:(NSInteger)section; //節對應的行數

 9.獲取Rect隊列

- (CGRect)rectForSection:(NSInteger)section;                                    // includes header, footer and all rows
- (CGRect)rectForHeaderInSection:(NSInteger)section;
- (CGRect)rectForFooterInSection:(NSInteger)section;
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;

 10.Info

//    //獲取point點處的NSIndexPath,若點不在任何table中的任意行則返回nil
//    - (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
//    //返回制定UITableViewCell對應的NSIndexPath,不可見返回nil
//    - (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell;
//    //返回矩形包含的NSIndexPath
//    - (NSArray *)indexPathsForRowsInRect:(CGRect)rect;
//     //獲取indexPath處的UITableViewCell,若cell不可見或indexPath超出邊界返回nil
//    - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
//    //返回可見的UITableViewCell
//    - (NSArray *)visibleCells;
//    //返回可見行的NSIndexPath數組
//    - (NSArray *)indexPathsForVisibleRows;
//    //獲取Section對應的headerViewForSection、footerViewForSection
//    - (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
//    - (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

 11.滾動

    //滾動到indexPath處
    - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
    //滾動到選擇的行處
    - (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;

 12.

//標記了一個tableView的動畫塊。分別表明動畫的開始開始和結束。二者成對出現,能夠嵌套使用。通常,在添加,刪除,選擇 tableView中使用,並實現動效果。在動畫塊內,不建議使用reloadData方法,若是使用,會影響動畫
    - (void)beginUpdates;
    - (void)endUpdates;

 13.對節、行的增刪改

 - (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 NS_AVAILABLE_IOS(5_0);

 14.修改

   //可選中 默認YES
    @property (nonatomic) BOOL allowsSelection NS_AVAILABLE_IOS(3_0);
    //編輯的時候是否可選中  默認NO
    @property (nonatomic) BOOL allowsSelectionDuringEditing;
    //可多選 默認NO
    @property (nonatomic) BOOL allowsMultipleSelection NS_AVAILABLE_IOS(5_0);
    //多選時是否可編輯 默認NO
    @property (nonatomic) BOOL allowsMultipleSelectionDuringEditing NS_AVAILABLE_IOS(5_0);

 15.選擇

 //選中行的NSIndexPath
    - (NSIndexPath *)indexPathForSelectedRow;
    //選中的多行的NSIndexPaths
    - (NSArray *)indexPathsForSelectedRows;
    //選中indexPath對應的行 滾動到行的位置
    - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
    //取消選擇
    - (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

 16.

//當咱們tableView中section有不少,數據量比較大的時候咱們能夠引入indexList,來方便完成section的定位,例如系統的通信錄程序。咱們能夠經過設置tableView的sectionIndexMinimumDisplayRowCount屬性來指定當tableView中多少行的時候開始顯示IndexList,默認NSIntegerMax,即默認不顯示indexList
    @property (nonatomic) NSInteger sectionIndexMinimumDisplayRowCount;

 17.

//節索引的文本顏色
    @property (nonatomic, retain) UIColor *sectionIndexColor
    //節索引的背景色
    @property (nonatomic, retain) UIColor *sectionIndexBackgroundColor
    //點擊時節索引背景色
    @property (nonatomic, retain) UIColor *sectionIndexTrackingBackgroundColor
    //單元格分割線的樣式
    @property (nonatomic) UITableViewCellSeparatorStyle separatorStyle;
    //設置單元格分割線的顏色
    @property (nonatomic, retain) UIColor              *separatorColor
    //單元格的毛玻璃效果
    @property (nonatomic, copy) UIVisualEffect               *separatorEffect
    //UITableView的HeaderView
    @property (nonatomic, retain) UIView *tableHeaderView;
    //UITableView的FooterView
    @property (nonatomic, retain) UIView *tableFooterView;

 18.

//獲取重用隊列中的單元格
    - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier;
    //ios6以後出現 須要與registerClass、registerNib配合使用
    - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
    //獲取HeaderFooterView 須要與registerClass、registerNib配合使用
    - (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
    - (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
相關文章
相關標籤/搜索