01.UITableView所有屬性,方法,數(shù)據(jù)源,代理方法解析

@(〓〓 iOS-基礎(chǔ)UI)[TableView 應(yīng)用]


目錄

  • 01.UITableView所有屬性,方法,數(shù)據(jù)源,代理方法解析
  • 1.UITableViewDelegate代理方法
    • cell,header,footer顯示相關(guān)的方法
    • 高度和估算高度代理方法
    • UITableView設(shè)置分組View的方法
    • TableViewCell輔助視圖方法
    • 操作cell時調(diào)用的方法
    • 編輯模式相關(guān)的代理方法
  • 2.UITableViewDataSource數(shù)據(jù)源方法
    • 必須實現(xiàn)的數(shù)據(jù)源方法
    • 可選實現(xiàn)的數(shù)據(jù)源方法
  • 3.UITableView的屬性和方法
  • UITableView的屬性和構(gòu)造方法
  • cell刷新方法
  • 獲取相關(guān)數(shù)據(jù)信息
  • 通過索引獲取數(shù)據(jù)
  • UITableView滾動方法
  • 插入,刪除,刷新,移動section組
  • 局部刷新TableView
  • 編輯狀態(tài)相關(guān)方法
  • 選中操作相關(guān)方法
  • 索引條設(shè)置
  • 分割線設(shè)置
    -緩沖池獲取cell(常用)
  • cell注冊方法(常用)
  • 4.分類方法
  • 5.UITableView枚舉類型
    • UITableView的所有枚舉類型
    • 獲取可見cell,header,footer
  • 6.UITableView的基本屬性,方法


1.UITableViewDelegate代理方法

cell,header,footer顯示相關(guān)的方法

// ----------------------------------------------------------------------------
// 顯示相關(guān)的代理方法

// 即將顯示tableviewcell時調(diào)用
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

// 即將顯示header時調(diào)用,在cell之后調(diào)用
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

// 即將顯示footer時調(diào)用,在header之后調(diào)用
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

// 在刪除cell之后調(diào)用,停止顯示cell的時候調(diào)用,界面不顯示cell時。
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath NS_AVAILABLE_IOS(6_0);

// 停止顯示header的時候調(diào)用
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

// 停止顯示footer的時候調(diào)用
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

高度和估算高度代理方法

// Variable height support
// ----------------------------------------------------------------------------
// 在設(shè)置每行cell的高度,header的高度,footer的高度
// 設(shè)置某行cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
// 設(shè)置header高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
// 設(shè)置footer高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;



// ----------------------------------------------------------------------------
// 設(shè)置每行cell的估算高度, header的估算高度, footer的估算高度
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(7_0);

// 對可變的header 高度的估算
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);
// 對可變的footer 高度的估算
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);

UITableView設(shè)置分組View的方法

// ----------------------------------------------------------------------------
// 設(shè)置第section分組的header
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
// 設(shè)置第section分組的footer
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
//返回uiview類型,返回的uiview 使用在section的footer部分


TableViewCell輔助視圖方法

// ----------------------------------------------------------------------------
// 輔助視圖 Accessories (disclosures).

// 設(shè)置某行cell的輔助視圖類型 已過期
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath NS_DEPRECATED_IOS(2_0, 3_0);

// 可手動調(diào)用,在其他的觸發(fā)事件中 傳入tableview 以及indexPath參數(shù),進行操作。
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;

操作cell時調(diào)用的方法


// ----------------------------------------------------------------------------
// cell操作時調(diào)用的方法

// 設(shè)置是否允許cell高亮狀態(tài)
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
// 按下cell未彈起時調(diào)用,即即將高亮?xí)r調(diào)用,如果return no 則點擊的時候沒有反應(yīng),但是還是會執(zhí)行此方法
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
// 按下cell彈起時調(diào)用
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);

//點擊時,有高亮顯示的時候 調(diào)用
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
//點擊cell,彈起時調(diào)用, 返回所點擊的indexpath
// 取消選中的使用調(diào)用 EX:如果選擇的時row1, 當(dāng)你點擊了row3時,返回1;
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

// cell選中時調(diào)用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
// cell取消選中時調(diào)用
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

編輯模式相關(guān)的代理方法



// ----------------------------------------------------------------------------
// 編輯模式模塊 Editing


// 返回每一行cell的編輯模式, 可以再次設(shè)置add或者刪除操作。
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
// cell左滑刪除時,刪除按鈕的標(biāo)題
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
// 自定義編輯左滑后出現(xiàn)的界面。  不止只有一個delete按鈕, 可以自行定義,返回一個數(shù)組。數(shù)組中放著UITableviewRowAction
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0);
// 未實現(xiàn) 默認為yes,進入編輯時,cell是否縮進。  在開啟編輯狀態(tài)時調(diào)用。
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;

// 右滑準(zhǔn)備進行編輯的時候 調(diào)用。 將setediting = yes時不調(diào)用
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
// 完成編輯的時候調(diào)用
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;



// ------------------------------------------------------------------------
// 編輯狀態(tài)下的操作

//在編輯狀態(tài)下,返回可以進行move的indexpath
// EX: 返回row =1;section =0; 則只能將其他cell往row1中移動。
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;

//設(shè)置cell的縮進。  返回indexPath.row
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath; // // Copy/Paste.  All three methods must be implemented by the delegate.

// 是否在指定行顯示菜單,返回值為YES時,長按顯示菜單
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(5_0);
// 彈出菜單后回調(diào)用此方法。
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender NS_AVAILABLE_IOS(5_0);
// 選擇菜單完成后,調(diào)用此方法。
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender NS_AVAILABLE_IOS(5_0);
@end

// cell選中時發(fā)送的通知
UIKIT_EXTERN NSString *const UITableViewSelectionDidChangeNotification;

2.UITableViewDataSource數(shù)據(jù)源方法

必須實現(xiàn)的數(shù)據(jù)源方法

// ------------------------------------------------------------------------
// 必須實現(xiàn)的數(shù)據(jù)源方法

// 返回第section組中有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// cell的內(nèi)容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

可選實現(xiàn)的數(shù)據(jù)源方法

// ------------------------------------------------------------------------
// 可選實現(xiàn)的數(shù)據(jù)源方法
@optional

// 返回多少組,沒實現(xiàn)該方法,默認為1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

// 返回某個section對應(yīng)的header標(biāo)題
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
// 返回某個section對應(yīng)的footer標(biāo)題
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

// Editing

// 設(shè)置cell為可編輯模式 與commitEditXXXX共同使用
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

// Moving/reordering

// Allows the reorder accessory view to optionally be shown for a particular row. By default, the reorder control will be shown only if the datasource implements -tableView:moveRowAtIndexPath:toIndexPath:
// 設(shè)置cell為可移動模式 與 tableview:moveXXXXX方法共同使用
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

// ----------------------------------------------------------------------------
// 索引條

//返回要顯示的section索引標(biāo)題
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
// return list of section titles to display in section index view (e.g. "ABCD...Z#")
// 點擊右側(cè)索引表項時調(diào)用
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;


// tell table which section corresponds to section title/index (e.g. "B",1))

// Data manipulation - insert and delete support

// After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change
// Not called for edit actions using UITableViewRowAction - the action's handler will be invoked instead
// 提交編輯
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

// Data manipulation - reorder / moving support

// 移動時使用
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;

3.UITableView的屬性和方法

UITableView的屬性和構(gòu)造方法

// cell的構(gòu)造方法,自定義cell時,如果要初始化設(shè)置cell屬性時,可以重寫該方法,在方法內(nèi)部設(shè)置
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;


// UITableView的類型: plain類型和group分組類型
@property (nonatomic, readonly) UITableViewStyle           style;
// 數(shù)據(jù)源
@property (nonatomic, assign)   id <UITableViewDataSource> dataSource;
// 代理
@property (nonatomic, assign)   id <UITableViewDelegate>   delegate;
// 設(shè)置所有cell的行高,默認44
@property (nonatomic)          CGFloat                     rowHeight;
// 分組頭部高度
@property (nonatomic)          CGFloat                     sectionHeaderHeight;
// 分組尾部高度
@property (nonatomic)          CGFloat                     sectionFooterHeight;
// cell估算高度,默認0
@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);
// 分割線內(nèi)邊距
@property (nonatomic)          UIEdgeInsets                separatorInset NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // allows customization of the frame of cell separators

// 背景view
@property(nonatomic, readwrite, retain) UIView *backgroundView NS_AVAILABLE_IOS(3_2); // the background view will be automatically resized to track the size of the table view.  this will be placed as a subview of the table view behind all cells and headers/footers.  default may be non-nil for some devices.

cell刷新方法

// ----------------------------------------------------------------------------
// cell數(shù)據(jù)刷新

// 重新載入tableview所有cell  一般是在數(shù)據(jù)源有改變的時候
- (void)reloadData;
// 重新載入,section的索引標(biāo)題。
- (void)reloadSectionIndexTitles NS_AVAILABLE_IOS(3_0);   // reloads the index bar.


獲取相關(guān)數(shù)據(jù)信息

// ----------------------------------------------------------------------------
// 獲取數(shù)據(jù)信息

// 獲取TableView共有多少組
- (NSInteger)numberOfSections;
// 獲取第section組共有多少行
- (NSInteger)numberOfRowsInSection:(NSInteger)section;

// 獲取某一組的frame,頭部frame,尾部frame,cell的frame
- (CGRect)rectForSection:(NSInteger)section;                                    // includes header, footer and all rows
- (CGRect)rectForHeaderInSection:(NSInteger)section;
- (CGRect)rectForFooterInSection:(NSInteger)section;
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;


通過索引獲取數(shù)據(jù)

// ----------------------------------------------------------------------------
// 索引獲取數(shù)據(jù)

// 返回指定點所在位置的indexPath
- (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;
// 返回指定cell所在的indexPath
- (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell;

// 返回指定范圍rect中的所有cell的indexPath
- (NSArray *)indexPathsForRowsInRect:(CGRect)rect;                              // returns nil if rect not valid

// 返回索引indexPath所指向的cell。
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;

UITableView滾動方法

// ----------------------------------------------------------------------------
// UITableViewCell滾動

// 根據(jù)傳入的indexPath,滾動到相對應(yīng)的位置,第二個參數(shù)是控制對應(yīng)的cell再滾動后處于tableview的頂部/底部/中部等
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
// 滾動到被選中項。  滾動后處于tableview的頂部/底部/中部等
- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
// Row insertion/deletion/reloading.

- (void)beginUpdates;   // allow multiple insert/delete of rows and sections to be animated simultaneously. Nestable
- (void)endUpdates;     // only call insert/delete/reload calls or change the editing state inside an update block.  otherwise things like row count, etc. may be invalid.


插入,刪除,刷新,移動section組



// ----------------------------------------------------------------------------
// 插入,刪除,刷新,移動section組
// 插入section
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
// 刪除section
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
// 刷新section
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:
(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
// 移動section
- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection NS_AVAILABLE_IOS(5_0);

局部刷新TableView


// ----------------------------------------------------------------------------
// 局部刷新cell: 插入,刪除,刷新,移動指定行cell

// 插入時局部刷新
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

// 刪除時局部刷新
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
// 更新某行cell
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
// 移動cell
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath NS_AVAILABLE_IOS(5_0);


編輯狀態(tài)相關(guān)方法


// Editing. When set, rows show insert/delete/reorder controls based on data source queries
// 編輯狀態(tài).
@property (nonatomic, getter=isEditing) BOOL editing;
// 設(shè)置編輯狀態(tài)已動畫顯示
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

@property (nonatomic) BOOL allowsSelection NS_AVAILABLE_IOS(3_0);  // default is YES. Controls whether rows can be selected when not in editing mode
@property (nonatomic) BOOL allowsSelectionDuringEditing;                                     // default is NO. Controls whether rows can be selected when in editing mode
@property (nonatomic) BOOL allowsMultipleSelection NS_AVAILABLE_IOS(5_0);                 // default is NO. Controls whether multiple rows can be selected simultaneously
@property (nonatomic) BOOL allowsMultipleSelectionDuringEditing NS_AVAILABLE_IOS(5_0);   // default is NO. Controls whether multiple rows can be selected simultaneously in editing mode

選中操作相關(guān)方法

// ----------------------------------------------------------------------------
// Selection

// 獲取選中行的indexPath
- (NSIndexPath *)indexPathForSelectedRow;
// 返回一個多行選中的indexpath數(shù)組
- (NSArray *)indexPathsForSelectedRows NS_AVAILABLE_IOS(5_0);

// 調(diào)用此方法,此indexpath的cell被選中,若此cell不再可視范圍內(nèi),自動按照最后一個參數(shù)的方式進行滾動
- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
// 取消此indexpath的選中狀態(tài)
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

索引條設(shè)置

// ----------------------------------------------------------------------------
// 索引條設(shè)置

@property (nonatomic) NSInteger sectionIndexMinimumDisplayRowCount;                                                      // show special section index list on right when row count reaches this value. default is 0
// 索引條字體顏色
@property (nonatomic, retain) UIColor *sectionIndexColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;                   // color used for text of the section index
// 索引條背景顏色
@property (nonatomic, retain) UIColor *sectionIndexBackgroundColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;         // the background color of the section index while not being touched
// 按住時,索引條顯示的背景顏色
@property (nonatomic, retain) UIColor *sectionIndexTrackingBackgroundColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR; // the background color of the section index while it is being touched

分割線設(shè)置

// ----------------------------------------------------------------------------
// 分割線設(shè)置

// 分割線的樣式
@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine
// 分割線顏色
@property (nonatomic, retain) UIColor              *separatorColor UI_APPEARANCE_SELECTOR; // default is the standard separator gray
// 分割線的玻璃效果
@property (nonatomic, copy) UIVisualEffect               *separatorEffect NS_AVAILABLE_IOS(8_0) UI_APPEARANCE_SELECTOR; // effect to apply to table separators

// ----------------------------------------------------------------------------
// tableHeaderView和tableFooterView
@property (nonatomic, retain) UIView *tableHeaderView;                           // accessory view for above row content. default is nil. not to be confused with section header
@property (nonatomic, retain) UIView *tableFooterView;                           // accessory view below content. default is nil. not to be confused with section footer


緩沖池獲取cell(常用)


// ----------------------------------------------------------------------------
// 從緩沖池獲取cell,header,footer

// 從緩沖池獲取cell
- (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
// 沖緩沖池獲取header,footer
- (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);  // like dequeueReusableCellWithIdentifier:, but for headers/footers

cell注冊方法



// ----------------------------------------------------------------------------
// 注冊cell,header,footer

// 注冊xib創(chuàng)建的cell
- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);
// 注冊cell
- (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

// 注冊xib創(chuàng)建的header,footer
- (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);
// 注冊header,footer
- (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

4.分類方法

// This category provides convenience methods to make it easier to use an NSIndexPath to represent a section and row
@interface NSIndexPath (UITableView)

+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;

@property(nonatomic,readonly) NSInteger section;
@property(nonatomic,readonly) NSInteger row;

@end

5.UITableView枚舉類型

UITableView的所有枚舉類型


// ----------------------------------------------------------------------------
// UITableView的類型   plain類型和group分組類型
typedef NS_ENUM(NSInteger, UITableViewStyle) {
    UITableViewStylePlain,                  // regular table view
    UITableViewStyleGrouped                 // preferences style table view
};

// ----------------------------------------------------------------------------
// 選中某一行后想要tableView自動滾動使得選中行始終處于table的top、middle或者bottom.
// 使用案例: 滾到指定行的cell到TableView的底部
// [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
typedef NS_ENUM(NSInteger, UITableViewScrollPosition) {
    UITableViewScrollPositionNone,
    UITableViewScrollPositionTop,
    UITableViewScrollPositionMiddle,
    UITableViewScrollPositionBottom
};

// ----------------------------------------------------------------------------
// 刪除/添加時,cell的動畫類型
typedef NS_ENUM(NSInteger, UITableViewRowAnimation) {
    UITableViewRowAnimationFade,
    UITableViewRowAnimationRight,           // slide in from right (or out to right)
    UITableViewRowAnimationLeft,
    UITableViewRowAnimationTop,
    UITableViewRowAnimationBottom,
    UITableViewRowAnimationNone,            // available in iOS 3.0
    UITableViewRowAnimationMiddle,          // available in iOS 3.2.  attempts to keep cell centered in the space it will/did occupy
    UITableViewRowAnimationAutomatic = 100  // available in iOS 5.0.  chooses an appropriate animation style for you
};

// ----------------------------------------------------------------------------
// 在編輯狀態(tài)下左劃cell時,cell右側(cè)顯示的按鈕類型
typedef NS_ENUM(NSInteger, UITableViewRowActionStyle) {
    UITableViewRowActionStyleDefault = 0,
    UITableViewRowActionStyleDestructive = UITableViewRowActionStyleDefault,
    UITableViewRowActionStyleNormal
} NS_ENUM_AVAILABLE_IOS(8_0);

獲取可見cell,header,footer


// 返回tableview中可見的cell
- (NSArray *)visibleCells;
// 返回一個NSArray,NSArray中向上包含tableview中 可見indexpath   ex:若你cell總數(shù)為50行,高亮的行數(shù)在20行,則返回0-19的index path
- (NSArray *)indexPathsForVisibleRows;

// 返回第section組的footerView 和 headerView
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);


6.UITableView的基本屬性,方法


// 創(chuàng)建左劃時顯示的按鈕
+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSString *)title handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;

// ------------------------------------------------------------------------
// 在編輯狀態(tài)下左劃cell時,cell右側(cè)顯示的按鈕類型
@property (nonatomic, readonly) UITableViewRowActionStyle style;
// tableView標(biāo)題
@property (nonatomic, copy) NSString *title;
// 背景顏色
@property (nonatomic, copy) UIColor *backgroundColor; // default background color is dependent on style
// 背景毛玻璃效果
@property (nonatomic, copy) UIVisualEffect* backgroundEffect;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容