天天看點

UITableView-iOS-Apple官方文檔翻譯注釋總結

<span style="font-size:18px;">//
//  UITableView.h
//  UIKit
//
//  Copyright (c) 2005-2015 Apple Inc. All rights reserved.
//


#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIScrollView.h>
#import <UIKit/UISwipeGestureRecognizer.h>
#import <UIKit/UITableViewCell.h>
#import <UIKit/UIKitDefines.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, UITableViewStyle) {
    UITableViewStylePlain,          // regular table view       普通類型
    UITableViewStyleGrouped         // preferences style table view     分組類型
};

// scrollPosition參數決定定位的相對位置
typedef NS_ENUM(NSInteger, UITableViewScrollPosition) {
    UITableViewScrollPositionNone,          // 同UITableViewScrollPositionTop
    UITableViewScrollPositionTop,           // 定位完成後,将定位的行顯示在tableView的頂部
    UITableViewScrollPositionMiddle,        // 定位完成後,将定位的行顯示在tableView的中間
    UITableViewScrollPositionBottom         // 定位完成後,将定位的行顯示在tableView的最下面
};                // scroll so row of interest is completely visible at top/center/bottom of view

// 行變化(插入、删除、移動的動畫類型)
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        // 自動選擇合适的動畫
};

// Including this constant string in the array of strings returned by sectionIndexTitlesForTableView: will cause a magnifying glass icon to be displayed at that location in the index.
// This should generally only be used as the first title in the index.
UIKIT_EXTERN NSString *const UITableViewIndexSearch NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;

// Returning this value from tableView:heightForHeaderInSection: or tableView:heightForFooterInSection: results in a height that fits the value returned from
// tableView:titleForHeaderInSection: or tableView:titleForFooterInSection: if the title is not nil.
UIKIT_EXTERN const CGFloat UITableViewAutomaticDimension NS_AVAILABLE_IOS(5_0);

@class UITableView;
@class UINib;
@protocol UITableViewDataSource;
@class UILongPressGestureRecognizer;
@class UITableViewHeaderFooterView;
@class UIRefreshControl;
@class UIVisualEffect;

typedef NS_ENUM(NSInteger, UITableViewRowActionStyle) {
    UITableViewRowActionStyleDefault = 0,
    UITableViewRowActionStyleDestructive = UITableViewRowActionStyleDefault,
    UITableViewRowActionStyleNormal
} NS_ENUM_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED;

NS_CLASS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED @interface UITableViewRowAction : NSObject <NSCopying>

+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(nullable NSString *)title handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;

@property (nonatomic, readonly) UITableViewRowActionStyle style;
@property (nonatomic, copy, nullable) NSString *title;
@property (nonatomic, copy, nullable) UIColor *backgroundColor; // default background color is dependent on style   預設背景顔色樣式
@property (nonatomic, copy, nullable) UIVisualEffect* backgroundEffect;

@end

NS_CLASS_AVAILABLE_IOS(9_0) @interface UITableViewFocusUpdateContext : UIFocusUpdateContext

@property (nonatomic, strong, readonly, nullable) NSIndexPath *previouslyFocusedIndexPath;
@property (nonatomic, strong, readonly, nullable) NSIndexPath *nextFocusedIndexPath;

@end

//_______________________________________________________________________________________________________________
// this represents the display and behaviour of the cells.          這邊是cell的顯示和行為

@protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>

@optional

// Display customization
// 将要展示cell/header/footer
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
// 完成展示cell/header/footer
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

// Variable height support      可變高度支援
// 每個cell、section-header、section-footer高度的傳回(這裡高度通過協定傳回,是為了table能準确的定位出來要顯示的Cell-index,進而滿足UITableView的重用機制)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

// Use the estimatedHeight methods to quickly calcuate guessed values which will allow for fast load times of the table.
// If these methods are implemented, the above -tableView:heightForXXX calls will be deferred until views are ready to be displayed, so more expensive logic can be placed there.
// 設定行高,頭視圖高度和尾視圖高度的估計值(對于高度可變的情況下,提高效率)
// https://www.shinobicontrols.com/blog/ios7-day-by-day-day-19-uitableview-row-height-estimation    //tableView估算高度網址
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(7_0);
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);
/*
 
 self.tableView.rowHeight=UITableViewAutomaticDimension;
 self.tableView.estimatedRowHeight=44.0;
 
 [cell setNeedsUpdateConstraints];
 [cell updateConstraintsIfNeeded];
 
 在 cellforrow 裡調用     [cell setNeedsUpdateConstraints];
 [cell updateConstraintsIfNeeded];
 
 要結合起來 我之前 用Storybord做cell自使用  就使用這個方法
 
 */




// Section header & footer information. Views are preferred over title should you decide to provide both
// 第section組頭部以及尾部顯示什麼控件
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;   // custom view for header. will be adjusted to default or specified header height
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;   // custom view for footer. will be adjusted to default or specified footer height



// Accessories (disclosures).

// 當cell的accessaryType為UITableViewCellAccessoryFetailDisclosureButton時,點選accessaryView将會調用delegate的tableView:accessoryButtonTappedForRowWithIndexPath方法。否則隻隻是didSelectRowAtIndexPath;   (accessaryView 輔助視圖)
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
// 設定每個單元格上面的按鈕的點選方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;

// Selection

// -tableView:shouldHighlightRowAtIndexPath: is called when a touch comes down on a row. 
// Returning NO to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.
// 目前選中的row是否高亮
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
// 指定row高亮
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
// 通知委托表視圖的指定行不在高亮顯示,一般是點選其他行的時候
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);

// Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.
// cell選擇和取消選擇
- (nullable NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (nullable NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
// Called after the user changes the selection.
// 已經選擇彙總和已經取消選擇選中後調用的函數
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
/* 先點選row1,再點選row2,兩者執行順序:在下一行将要選中後才取消上一行的選中
 willSelectRowAtIndexPath 目前row為:0
 didSelectRowAtIndexPath 目前row為:0
 willSelectRowAtIndexPath 目前row為:1
 willDeselectRowAtIndexPath 目前row為:0
 didDeselectRowAtIndexPath 目前row為:0
 didSelectRowAtIndexPath 目前row為:1
 */


// Editing      編輯

// Allows customization of the editingStyle for a particular cell located at 'indexPath'. If not implemented, all editable cells will have UITableViewCellEditingStyleDelete set for them when the table has editing property set to YES.
// 設定tableView被編輯時的狀态風格,如果不設定,預設是删除風格
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
// 自定義删除按鈕的标題
- (nullable NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED;
// 用于自定義建立tableView被編輯時右邊的按鈕,按鈕類型為UITableViewRowAction
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED; // supercedes -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath: if return value is non-nil

// Controls whether the background is indented while editing.  If not implemented, the default is YES.  This is unrelated to the indentation level below.  This method only applies to grouped style table views.
// 設定編輯模式下是否需要對表視圖指定行進行縮進,NO為關閉縮進,這個方法可以用來去掉move時row前面的空白
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;

// The willBegin/didEnd methods are called whenever the 'editing' property is automatically changed by the table (allowing insert/delete/move). This is done by a swipe activating a single row
// 開始編輯前調用
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath __TVOS_PROHIBITED;
// 完成編輯後調用
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath __TVOS_PROHIBITED;

// Moving/reordering

// Allows customization of the target row for a particular row as it is being moved/reordered
// 移動特定的某行(注意差別之前的tableView:moveRowAtIndexPath:toIndexPath方法。當手指按住reorde accessory view移動時,隻要有row moved/reordered都會調用該方法,而前者方法隻有當手指放開reorder accessory view時,結束move/order操作才會調用自己。傳回值代表進行移動操作後回到的行,如果設定為目前行,則不論怎麼移動都會回到目前行)
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;               

// Indentation
// 行縮進
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath; // return 'depth' of row for hierarchies

// Copy/Paste.  All three methods must be implemented by the delegate.
// 長按出來的Copy/Paste操作 (複制粘貼)----->通知委托是否在指定行顯示菜單,傳回值為YES時,長按顯示菜單
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(5_0);
// 彈出選擇菜單時會調用此方法(複制、粘貼、全選、剪切)
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(nullable id)sender NS_AVAILABLE_IOS(5_0);
// 選擇菜單項完成之後調用此方法
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(nullable id)sender NS_AVAILABLE_IOS(5_0);

// Focus 焦點

- (BOOL)tableView:(UITableView *)tableView canFocusRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(9_0);
- (BOOL)tableView:(UITableView *)tableView shouldUpdateFocusInContext:(UITableViewFocusUpdateContext *)context NS_AVAILABLE_IOS(9_0);
- (void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator NS_AVAILABLE_IOS(9_0);
- (nullable NSIndexPath *)indexPathForPreferredFocusedViewInTableView:(UITableView *)tableView NS_AVAILABLE_IOS(9_0);

@end

UIKIT_EXTERN NSString *const UITableViewSelectionDidChangeNotification;     // 通知


//_______________________________________________________________________________________________________________

NS_CLASS_AVAILABLE_IOS(2_0) @interface UITableView : UIScrollView <NSCoding>

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style NS_DESIGNATED_INITIALIZER; // must specify style at creation. -initWithFrame: calls this with UITableViewStylePlain
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;

@property (nonatomic, readonly) UITableViewStyle style;     // 清單視圖的類型,隻讀
@property (nonatomic, weak, nullable) id <UITableViewDataSource> dataSource;
@property (nonatomic, weak, nullable) id <UITableViewDelegate> delegate;
@property (nonatomic) CGFloat rowHeight;             // will return the default value if unset      行高
@property (nonatomic) CGFloat sectionHeaderHeight;   // will return the default value if unset      組頭的高度
@property (nonatomic) CGFloat sectionFooterHeight;   // will return the default value if unset      組尾的高度
@property (nonatomic) CGFloat estimatedRowHeight NS_AVAILABLE_IOS(7_0); // default is 0, which means there is no estimate       估算行高,預設0
@property (nonatomic) CGFloat estimatedSectionHeaderHeight NS_AVAILABLE_IOS(7_0); // default is 0, which means there is no estimate     估算組頭的高度
@property (nonatomic) CGFloat estimatedSectionFooterHeight NS_AVAILABLE_IOS(7_0); // default is 0, which means there is no estimate     估算組尾的高度
@property (nonatomic) UIEdgeInsets separatorInset NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // allows customization of the frame of cell separators     允許更改分割線的frame

@property (nonatomic, strong, nullable) 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.         背景視圖(自動比對tableView視圖大小),設定互作為清單視圖的子視圖,切在所有cell和headers/footers的後面,預設為nil

// Data     資料的重新整理

- (void)reloadData; // reloads everything from scratch. redisplays visible rows. because we only keep info about visible rows, this is cheap. will adjust offset if table shrinks       重新整理清單
- (void)reloadSectionIndexTitles NS_AVAILABLE_IOS(3_0);   // reloads the index bar.         重新整理你section這個方法常用語新加或者删除了索引類别二無需率先呢整個表視圖的情況下

// Info     資訊

@property (nonatomic, readonly) NSInteger numberOfSections;     // 清單的組數
- (NSInteger)numberOfRowsInSection:(NSInteger)section;          // 某一組有多少行

- (CGRect)rectForSection:(NSInteger)section;                                    // includes header, footer and all rows     某一組所占的矩形區域(包括header,footer和所有的行)
- (CGRect)rectForHeaderInSection:(NSInteger)section;            // 某一組的header所占的矩形區域
- (CGRect)rectForFooterInSection:(NSInteger)section;            // 某一組的footer所占的矩形區域
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;       // 某一分區的row所占的矩形區域

- (nullable NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point;                         // returns nil if point is outside of any row in the table     某一點在tableView上所占的分區,如果該點不在tableView的任何row上傳回nil
- (nullable NSIndexPath *)indexPathForCell:(UITableViewCell *)cell;                      // returns nil if cell is not visible      某一行所在的分區,如果改行是不可見的傳回nil
- (nullable NSArray<NSIndexPath *> *)indexPathsForRowsInRect:(CGRect)rect;                              // returns nil if rect not valid        某一矩形區域内所有行所在的所有分區,傳回元素為NSIndexPath類型的數組。當該矩形是一個無效值時,傳回nil

- (nullable __kindof UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;   // returns nil if cell is not visible or index path is out of range        某一分區的cell沒如果改cell是不可見的或者indexPath超出了傳回則傳回nil
@property (nonatomic, readonly) NSArray<__kindof UITableViewCell *> *visibleCells;      // 所有可見的cell,隻讀數組型(數組類型為UITableViewCell)
@property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForVisibleRows;     // 所有可見行所在的分區,隻讀數組型(NSIndexPath)

- (nullable UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);       // 某一組的header視圖(常用語自定義headerView用)
- (nullable UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);       // 某一組的footer視圖(常用語自定義footerView用)

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;     //使表視圖定位到某一位置(行)
- (void)scrollToNearestSelectedRowAtScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;   // 使表視圖定位到選中行

// Row insertion/deletion/reloading.
// 這兩個方法,是配合起來使用的,标記了一個tableView的動畫快。分别代表動畫的開始和結束。兩者成對出現,可以嵌套使用。一般,在添加,删除,選擇tableView中使用,并實作動畫效果。在動畫快内,不建議使用reloadData方法,如果使用,會影響動畫
- (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.      隻調用插入/删除/重載呼叫或改變一更新區塊内的編輯狀态。然而對于行數等屬性可能是無效的

- (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);           // 一定組section到組newSection的位置

- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;    // 插入某些行
- (void)deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;    // 删除某些行


- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);  // 重新整理tableView指定行的資料
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath NS_AVAILABLE_IOS(5_0);      // 移動分區indexPath的行到分區newIndexPath

// Editing. When set, rows show insert/delete/reorder controls based on data source queries     編輯、設定之後,行的顯示會基于資料源查詢插入/删除/重排序的控制

@property (nonatomic, getter=isEditing) BOOL editing;                             // default is NO. setting is not animated.    // 設定是否是編輯狀态(編輯狀态下的cell左邊會出現一個減号,編輯右邊會劃出删除按鈕)
- (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    當不再編輯模式時,是否可以選中,預設YES
@property (nonatomic) BOOL allowsSelectionDuringEditing;                                 // default is NO. Controls whether rows can be selected when in editing mode       當處在編輯模式時,是否可以選中。預設NO
@property (nonatomic) BOOL allowsMultipleSelection NS_AVAILABLE_IOS(5_0);                // default is NO. Controls whether multiple rows can be selected simultaneously        是否可以同時選中。預設NO
@property (nonatomic) BOOL allowsMultipleSelectionDuringEditing NS_AVAILABLE_IOS(5_0);   // default is NO. Controls whether multiple rows can be selected simultaneously in editing mode        當處在編輯模式時,是否可以同時選中。預設NO

// Selection        選中

@property (nonatomic, readonly, nullable) NSIndexPath *indexPathForSelectedRow; // returns nil or index path representing section and row of selection.     選中的行所在的分區(單選)
@property (nonatomic, readonly, nullable) NSArray<NSIndexPath *> *indexPathsForSelectedRows NS_AVAILABLE_IOS(5_0); // returns nil or a set of index paths representing the sections and rows of the selection.      選中的行所在的所有分區(多選)

// Selects and deselects rows. These methods will not call the delegate methods (-tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath:), nor will it send out a notification.      代碼收到選中與取消選中某行,注意:這兩個方法将不會回調代理中的方法
- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

// Appearance       外觀

@property (nonatomic) NSInteger sectionIndexMinimumDisplayRowCount;                                                      // show special section index list on right when row count reaches this value. default is 0        設定索引欄最小顯示行數。先睡先在右側專門章節索引清單當行數達到此值。預設值是0
@property (nonatomic, strong, nullable) UIColor *sectionIndexColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;                   // color used for text of the section index      設定索引欄字型顔色
@property (nonatomic, strong, nullable) UIColor *sectionIndexBackgroundColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;         // the background color of the section index while not being touched     設定索引欄背景顔色
@property (nonatomic, strong, nullable) UIColor *sectionIndexTrackingBackgroundColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR; // the background color of the section index while it is being touched       設定索引欄被選中時的顔色

@property (nonatomic) UITableViewCellSeparatorStyle separatorStyle __TVOS_PROHIBITED; // default is UITableViewCellSeparatorStyleSingleLine     設定分割線的風格
@property (nonatomic, strong, nullable) UIColor *separatorColor UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED; // default is the standard separator gray     設定分割線顔色
@property (nonatomic, copy, nullable) UIVisualEffect *separatorEffect NS_AVAILABLE_IOS(8_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED; // effect to apply to table separators        設定分割線毛玻璃效果(iOS8之後可用)

@property (nonatomic) BOOL cellLayoutMarginsFollowReadableWidth NS_AVAILABLE_IOS(9_0); // if cell margins are derived from the width of the readableContentGuide.

@property (nonatomic, strong, nullable) UIView *tableHeaderView;                           // accessory view for above row content. default is nil. not to be confused with section header      設定tableView頭視圖
@property (nonatomic, strong, nullable) UIView *tableFooterView;                           // accessory view below content. default is nil. not to be confused with section footer      設定tableView尾視圖

- (nullable __kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;  // Used by the delegate to acquire an already allocated cell, in lieu of allocating a new one.        從複用池張取cell
- (__kindof UITableViewCell *)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       擷取一個已注冊的cell
- (nullable __kindof UITableViewHeaderFooterView *)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);  // like dequeueReusableCellWithIdentifier:, but for headers/footers     從複用池擷取頭視圖或尾視圖

// Beginning in iOS 6, clients can register a nib or class for each cell.
// If all reuse identifiers are registered, use the newer -dequeueReusableCellWithIdentifier:forIndexPath: to guarantee that a cell instance is returned.
// Instances returned from the new dequeue method will also be properly sized when they are returned.
- (void)registerNib:(nullable UINib *)nib forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(5_0);          // 通過xib檔案注冊cell
- (void)registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);    // 通過oc類注冊cell

- (void)registerNib:(nullable UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);  // 通過xib檔案注冊頭視圖和尾視圖
- (void)registerClass:(nullable Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);   // 通過OC類注冊頭視圖和尾視圖

// Focus

@property (nonatomic) BOOL remembersLastFocusedIndexPath NS_AVAILABLE_IOS(9_0); // defaults to NO. If YES, when focusing on a table view the last focused index path is focused automatically. If the table view has never been focused, then the preferred focused index path is used.

@end

//_______________________________________________________________________________________________________________
// this protocol represents the data model object. as such, it supplies no information about appearance (including the cells)

@protocol UITableViewDataSource<NSObject>

@required

// 每個section下cell的個數(必須實作)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

// 通過Indexpath傳回具體的cell(必須實作)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

@optional

// 傳回有多少個section(預設是1)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              // Default is 1 if not implemented

// 每個section上面的智語内容
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different
// 每個section下面的智語内容
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

// Editing

// Individual rows can opt out of having the -editing property set for them. If not implemented, all rows are assumed to be editable.
// 是否可編輯
- (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:
// 是否可拖拽
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

// Index

// 右側索引條需要的數組内容
- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView __TVOS_PROHIBITED;                                                    // return list of section titles to display in section index view (e.g. "ABCD...Z#")
// 索引值對應的section-index
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index __TVOS_PROHIBITED;  // 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
// 對Cell編輯後的回調
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

// Data manipulation - reorder / moving support
// 對Cell拖拽後的回調
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;

@end

//_______________________________________________________________________________________________________________

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

// 類方法
+ (instancetype)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;

@property (nonatomic, readonly) NSInteger section;      // indexPath的組
@property (nonatomic, readonly) NSInteger row;          // indexPath的行

@end

NS_ASSUME_NONNULL_END</span>
           

一般執行順序如下:

<span style="font-size:18px;">/*
 ----dataSource/delegate方法大概執行順序(所有方法均實作):
 1).numberOfSectionsInTableView;有多少section,例如k;
 2).tableView:estimatedHeightForHeaderInSection + tableView:estimatedHeightForFooterInSection;計算k-1 section的header、footer大概高度;
 3).tableView:numberOfRowsInSection;k-1 section有多少 row;
 4).tableView:estimatedHeightForRowAtIndexPath;計算k-1 section中所有row的大概高度;
 5).重複1)~4)步驟,直到所有0至k-1的section計算完;
 6).sectionIndexTitlesForTableView;索引titles;
 7).tableView:heightForRowAtIndexPath;依次計算visible區域(螢幕區域)裡每個cell的高度(這裡的所有cell記做集合A,決定于螢幕高度和estimatedHeightForXXX方法)
 8).tableView:cellForRowAtIndexPath;建立第一個indexPath上的cell
 9).tableView:indentationLevelForRowAtIndexPath; indexPath上的cell的縮進;
 10).tableView:canEditRowAtIndexPath; indexPath上的cell編輯屬性;
 11).tableView:willDisplayCell:forRowAtIndexPath; indexPath上的cell将要顯示;
 12),重複8)~11),直到所有visible區域cell(集合A)建立完畢;
 13).tableView:heightForHeaderInSection + tableView:heightForFooterInSection + tableView:viewForHeaderInSection + tableView:viewForHeaderInSection;依次計算visible區域裡所有section 的header高度、footer高度、viewForHead、viewForFooter;
 
 
 
 
 
 ----執行順序(沒有實作estimatedHeight這些方法):
 1).numberOfSectionsInTableView;有多少section,例如k;
 2).tableView:heightForHeaderInSection + tableView:heightForFooterInSection;計算k-1 section的header、footer高度;
 3).tableView:numberOfRowsInSection;k-1 section有多少 row;
 4).tableView:heightForRowAtIndexPath;計算k-1 section中所有row得高度;
 5).重複1)~4)步驟,直到所有0至k-1的section計算完
 6).sectionIndexTitlesForTableView;索引titles;
 7).tableView:cellForRowAtIndexPath;建立第一個indexPath上的cell
 8).tableView:indentationLevelForRowAtIndexPath; indexPath上的cell的縮進;
 9).tableView:canEditRowAtIndexPath; indexPath上的cell編輯屬性;
 10).tableView:willDisplayCell:forRowAtIndexPath; indexPath上的cell将要顯示;
 12).重複7)~12),知道所有visible區域(螢幕)cell建立完畢;
 13).tableView:viewForHeaderInSection + tableView:viewForHeaderInSection;依次計算visible區域裡所有的viewForHead、viewForFooter;
 備注:
 1.由上可看出,estimatedHeight在加載tableview的時候代替了heightFor方法,heightFor方法隻有當cell需要顯示的時候,才會調用。
 2.關于estimatedHeightForXXX相關方法,裡面的傳回值并不能随意填寫的,應該是真實高度的大概值;因為在加載tableview的時候,當所有的section header/footer row的高度都大概計算完,開始計算高度、并建立visible區域的cell時候,這些cell屬不屬于visible區域的判斷依據就是之前的estimatedHeightForXXX方法傳回的值算出來的;例如estimatedHeightForXXX相關方法傳回值過大,算出來目前visible(螢幕)區域,包含3個section header 、footer以及裡面的row,是以實際建立的時候也是建立這些cell(參考上文中方法執行順序),當這些cell建立完,實際情況高度(heightForXXX方法所得)可能隻占visible(螢幕)區域的一半,導緻螢幕另一半空白。注意visible區域初始顯示的cell是由estimatedHeightForXXX相關方法決定的,而不是heightForXXX這些方法真實高度決定的,是以有時tableview中visible區域尾部cell顯示不出來或者建立的cell比visible區域cell多,都是estimatedHeightForXXX和heightForXXX方法相差導緻的原因。
 3.以上方法和ViewController那些方法關系:先執行viewdidload、willAppear等相關方法,再執行numberOfSectionsInTableView系列方法。
 */</span>
           

UItableView用法總結

<span style="font-size:24px;">UITableView</span>

<span style="font-size:14px;">UITableView内置了兩種樣式:UITableViewStylePlain,UITableViewStyleGrouped

<UITableViewDataSource,UITableViewDelegate]] > 裡的方法:
tableView處理步驟
#pragma mark 1.有多少組
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
#pragma mark 2.第section組頭部控件有多高
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
#pragma mark 3.第section組有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
#pragma mark 4.indexPath這行的cell有多高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
#pragma mark 5.indexPath這行的cell長什麼樣子
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
#pragma mark 6.第section組頭部顯示什麼控件
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

//每當有一個cell進入視野螢幕就會調用,是以在這個方法内部就需要優化。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(cell==nil){
//在這裡面做建立的工作。循環優化。防止重新整理cell進入螢幕的時候重複的建立
}
}

//當調用reloadData的時候,會重新重新整理調用資料源内所有方法,其他事情都不會做呀
 [self reloadData]

 //這個方法隻有在一開始有多少條資料才會算多少個高度,這個方法隻會調用一次,但是每次reloadData的時候也會調用
 //而且會一次性算出所有cell的高度,比如有100條資料,一次性調用100次
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath



-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView //右側索引

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath //行點選事件

NSIndexPath *path = [self.tableView indexPathForSelectedRow]; //獲得被選中的indexPath可以得到section,row
  
[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForSelectedRows] withRowAnimation:UITableViewRowAnimationNone]; //重新整理table指定行的資料
        
[self.tableView reloadData]; //重新整理table所有行的資料


UITableView常用屬性:
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain]; // 初始化表格
    分隔線屬性 
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; //UITableViewCellSeparatorStyleNone;
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; //取消分隔線
    tableView.separatorColor = [UIColor lightGrayColor];
   
    條目多選
tableView.allowsMultipleSelection = YES;
    
    // 設定标題行高
    [_tableView setSectionHeaderHeight:kHeaderHeight];
    [_tableView setSectionFooterHeight:0];

    // 設定表格行高
    [_tableView setRowHeight:50];

//設定背景色
self.tableView.backgroundView  優先級高,如果要設定backgroundColor的時候要先把view設定為nil
self.tableView.backgroundColor

//在tableView的頭部或者尾部添加view,footerView寬度是不用設定的
    xxxView.bounds = CGRectMake(0,0,0,height);
    self.tableView.tableFooterView =xxxView;
    self.tableView.tableHeaderView =xxxView;

UIButton *bt = (UIButton*)[self.contentView viewWithTag:i+100];
 
增加tableview滾動區域
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, xx, 0); </span>



<span style="font-size:24px;">UITableViewCell</span>
<span style="font-size:14px;">
//建立UITableViewCell        
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
       
[cell.textLabel setBackgroundColor:[UIColor clearColor]];// 清空标簽背景顔色 
       
        cell.backgroundView =xx; //設定背景圖檔
        cell.backgroundVColor =xx;
        cell.selectedBackgroundView = selectedBgView; //設定選中時的背景顔色

      
   cell.accessoryView = xxxView; //設定右邊視圖
   [cell setAccessoryType:UITableViewCellAccessoryNone]; //設定右側箭頭
 
[self setSelectionStyle:UITableViewCellSelectionStyleNone]; //選中樣式
cell.selectionStyle = UITableViewCellSelectionStyleBlue;

//設定cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

contentView下預設有3個子視圖,其中的2個是UILabel,通過textLabel和detailTextLabel屬性通路,第3個是UIImageView,通過imageView屬性通路.
  UITableViewCellStyleDefault, UITableViewCellStyleValue1, UITableViewCellStyleValue2, UITableViewCellStyleSubtitle
 
#pragma mark - 重新調整UITalbleViewCell中的控件布局
- (void)layoutSubviews{
[super layoutSubviews];
…
}</span>

<strong><span style="font-size:24px;">UITableViewCell表格優化</span>
<span style="font-size:18px;">UITableViewCell對象的重用原理:
重用原理:當滾動清單時,部分UITableViewCell會移出視窗,UITableView會将視窗外的UITableViewCell放入一個對象池中,等待重用。當UITableView要求dataSource傳回UITableViewCell時,dataSource會先檢視這個對象池,如果池中有未使用的UITableViewCell,dataSource會用新的資料配置這個UITableViewCell,然後傳回給UITableView,重新顯示到視窗中,進而避免建立新對象
還有一個非常重要的問題:有時候需要自定義UITableViewCell(用一個子類繼承UITableViewCell),而且每一行用的不一定是同一種UITableViewCell(如短信聊天布局),是以一個UITableView可能擁有不同類型的UITableViewCell,對象池中也會有很多不同類型的UITableViewCell,時可能會得到錯誤類型的UITableViewCell那麼UITableView在重用UITableViewCell。解決方案:UITableViewCell有個NSString *reuseIdentifier屬性,可以在初始化UITableViewCell的時候傳入一個特定的字元串辨別來設定reuseIdentifier(一般用UITableViewCell的類名)。當UITableView要求dataSource傳回UITableViewCell時,先通過一個字元串辨別到對象池中查找對應類型的UITableViewCell對象,如果有,就重用,如果沒有,就傳入這個字元串辨別來初始化一個UITableViewCell對象
</span></strong>
<span style="font-size:14px;">/**
單元格優化
 1. 标示符統一,使用static的目的可以保證表格标示符永遠隻有一個
 2. 首先在緩沖池中找名為"myCell"的單元格對象
 3. 如果沒有找到,執行個體化一個新的cell
 **/
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"myCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//使用這種方法不用判斷下面的cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    if (cell == nil) {       
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
return cell;
}</span>

<strong><span style="font-size:24px;">表格的編輯模式</span></strong>
<span style="font-size:14px;">//删除、插入 
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;  開啟表格編輯狀态 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
傳回表格編輯編輯樣式。不實作預設都是删除
return editingStyle : UITableViewCellEditingStyleDelete, UITableViewCellEditingStyleInsert
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
  //根據editingStyle處理是删除還是添加操作
  完成删除、插入操作重新整理表格
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

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

//移動
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
//sourceIndexPath 移動的行
//destinationIndexPath 目标的行</span>

<strong><span style="font-size:24px;">自定義表格行UITableViewCell</span></strong>
<span style="font-size:14px;">storyboard方式建立:
直接拖到UITableView裡面設定UITableViewCell
注意:
1.通過XIB或者Storyboard自定義單元格時,在xib和Storyboard裡面需要指定單元格的可重用标示符Identifier

2.注意表格的優化中的差别
在Storyboard中兩者等效
xxCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
xxCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

在xib檔案中有差别:
第一種情況,隻能在iOS 6以上使用,如果在viewDidLoad注冊了nib檔案,并且指定了“單元格”的可重用标示符,那麼    
     dequeueReusableCellWithIdentifier:
     dequeueReusableCellWithIdentifier:forIndexPath:
     方法是等效的。如果在viewDidLoad中注冊了nib檔案,表格緩沖池中的管理,有系統接管!

第二種情況,是在iOS 4以上均可以使用,如果沒有在viewDidLoad注冊nib檔案,那麼,隻能使用
     dequeueReusableCellWithIdentifier:并且需要判斷cell沒有被執行個體化,并做相應的處理

 
在代碼建立中差别:
用代碼建立cell中的處理和nib一樣,注冊了cell就有系統接管并且可以用帶forIndexPath的方法,沒有注冊就要自己去執行個體化cell,不能用帶forIndexPath的方法
[tableView registerClass:XxxCell class] forCellReuseIdentifier:@"xxCell"];

xib方式建立:
//注冊Identifier 
- (void)viewDidLoad{
    [super viewDidLoad];
    /**

//轉載請注明出處--本文永久連結:http://www.cnblogs.com/ChenYilong/p/3495919.html


     注意:以下幾句注冊XIB的代碼,一定要在viewDidLoad中!
     注冊XIB檔案,獲得根視圖,并且轉換成TableView,為tableView注冊xib
     Identifier名要在xib檔案中定義,并且保持一緻
     **/
    UINib *nib = [UINib nibWithNibName:@"BookCell" bundle:[NSBundle mainBundle]];
    UITableView *tableView = (UITableView *)self.view;
    [tableView registerNib:nib forCellReuseIdentifier:@"bookCell"];   
}

//沒有注冊Identifier隻能使用下面方法
static NSString *CellIdentifier = @"bookCell";
BookCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
        cell = [[BookCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        NSBundle *bundle = [NSBundle mainBundle];
        NSArray *array = [bundle loadNibNamed:@"BookCell" owner:nil options:nil];
        cell = [array lastObject];
    }


代碼方式建立:
建立UITableViewCell的類,繼承UITableViewCell
往cell裡面加入view的時候注意點:
//建立的元件放入contentView中
[self.contentView addSubview:xxView]; 

//設定圖檔拉伸屬性stretch
UIImage *normalImage = [UIImage imageNamed:@"xx.png"];
normalImage = [normalImage stretchableImageWithLeftCapWidth:
normalImage.size.width / 2 topCapHeight:normalImage.size.height / 2];

//在tableView裡面viewDiDLoad裡面要注冊cell類
[tableView registerClass:XxxCell class] forCellReuseIdentifier:@"xxCell"];</span>

<strong><span style="font-size:24px;">自定義表格中Header</span></strong>
<span style="font-size:14px;">//自定義表格在這個方法中定義
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section</span>