tableView 相關(guān)屬性和方法

1郭怪、初始化一個UITableView

1 - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
1 struct CGRect {
2    CGPoint origin;
3    CGSize size;
4 };
5 typedef struct CGRect CGRect;
1 typedef enum {
2    UITableViewStylePlain, //平鋪樣式
3    UITableViewStyleGrouped //分組樣式
4 } UITableViewStyle;

2、配置一個TableView

1)返回這個TableView的樣式(只讀屬性)

1 @property(nonatomic, readonly) UITableViewStyle style

2)返回指定section內(nèi)的Cell的行數(shù)

1 - (NSInteger)numberOfRowsInSection:(NSInteger)section

當(dāng)TableView在UITableViewStylePlain下section應(yīng)該為0

3)返回TableView的section數(shù)量

1 - (NSInteger)numberOfSections

4)設(shè)置TableView中所有cell的高度

1 @property(nonatomic) CGFloat rowHeight

Apple建議我們使用代理方法tableView:heightForRowAtIndexPath:代替rowHeight方法使TableView的性能更高

5)設(shè)置TableView的分隔線的樣式

1 @property(nonatomic) UITableViewCellSeparatorStyle separatorStyle
1 typedef enum : NSInteger {
2    UITableViewCellSeparatorStyleNone, //無分隔線
3    UITableViewCellSeparatorStyleSingleLine, //單分割線
4    UITableViewCellSeparatorStyleSingleLineEtched //被侵蝕的但分隔線
5 } UITableViewCellSeparatorStyle;

6)設(shè)置TableView的分隔線顏色

1 @property(nonatomic, retain) UIColor *separatorColor

7)設(shè)置TableView的背景視圖

1 @property(nonatomic, readwrite, retain) UIView *backgroundView

8)設(shè)置TableView的分隔線偏移量

1 @property (nonatomic) UIEdgeInsets separatorInset
2 //Available in iOS 7.0 and later.

Apple的例子

1 tableView.separatorInset = UIEdgeInsetsMake(0, 3, 0, 11);
                                             //上、左、下、右

3伊约、創(chuàng)建TableView的Cell

1)注冊一個包含指定標(biāo)示符TableView的Cell的nib對象

1  - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier //兩個參數(shù)不能是nil
2 //Available in iOS 5.0 and later.

2)注冊一個類用來創(chuàng)建新的Cell

1 - (void)registerClass:(Class)cellClass forCellReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.

3)使用指定的標(biāo)示符返回可重用的Cell

1 - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath
2 //Available in iOS 6.0 and later.

Apple重要提示:使用這個方法之前必須是使用了registerNib:forCellReuseIdentifier: 或者 registerClass:forCellReuseIdentifier:方法注冊了Cell

4)使用指定的標(biāo)示符返回可重用的Cell

1 - (id)dequeueReusableCellWithIdentifier:(NSString *)identifier

4词顾、訪問表頭和表尾的視圖

header通過下面兩個代理方法設(shè)置

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

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

footer通過下面兩個

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
如果要做整個tableview的header和footer,要通過tableview setHeaderView setFooterView```
讓表頭表尾視圖跟著tableView移動需要把tableView的樣式設(shè)為`group`

1)注冊一個包含表頭或表尾的指定標(biāo)示符表視圖的nib對象

1 - (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.```

2)注冊一個類碱妆,用來創(chuàng)建新的包含表頭或表尾的表視圖

1 - (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.```

3)返回一個指定標(biāo)識符的可重用的附帶表頭表尾的視圖

1 - (id)dequeueReusableHeaderFooterViewWithIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.```

4)設(shè)置或返回該表格的表頭視圖

1 @property(nonatomic, retain) UIView *tableHeaderView

5)設(shè)置或返回該表格的表尾視圖

1 @property(nonatomic, retain) UIView *tableFooterView

6)設(shè)置或返回該表格的表頭高度

1 @property(nonatomic) CGFloat sectionHeaderHeight```
7)設(shè)置或返回該表格的表尾高度

1 @property(nonatomic) CGFloat sectionFooterHeight```
8)返回指定section的表頭視圖

1 - (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
2 //Available in iOS 6.0 and later.```
9)返回指定section的表尾視圖

1 - (UITableViewHeaderFooterView *)footerViewForSection:(NSInteger)section
2 //Available in iOS 6.0 and later.```

5、訪問Cell和Section

1)返回指定indexPath的Cell

1 - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath```
2)返回指定Cell的IndexPath

1 - (NSIndexPath *)indexPathForCell:(UITableViewCell *)cell```
3)返回指定點的IndexPath

1 - (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point```
4)返回指定區(qū)域內(nèi)的IndexPath組成的數(shù)組

1 - (NSArray *)indexPathsForRowsInRect:(CGRect)rect```
5)返回可見的UITableViewCell組成的數(shù)組

1 - (NSArray *)visibleCells```
6)返回可見表格行的IndexPath組成的數(shù)組

1 - (NSArray *)indexPathsForVisibleRows```

6昔驱、估算元素的高度

1)設(shè)置表格行的估算高度以改善性能

1 @property (nonatomic) CGFloat estimatedRowHeight
2 //The default value is 0, which means there is no estimate.
3 //Available in iOS 7.0 and later.```
2)設(shè)置Section頭的估算高度以改善性能

1 @property(nonatomic) CGFloat estimatedSectionHeaderHeight
2 //The default value is 0, which means there is no estimate.
3 //Available in iOS 7.0 and later.```
3)設(shè)置Section尾的古都按高度以改善性能

1 @property(nonatomic) CGFloat estimatedSectionFooterHeight
2 //The default value is 0, which means there is no estimate.
3 //Available in iOS 7.0 and later.```
 ###7疹尾、滾動TableView

1)滾動到指定的位置

1 - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated```

1 typedef enum {
2    UITableViewScrollPositionNone,
3    UITableViewScrollPositionTop,
4    UITableViewScrollPositionMiddle,
5    UITableViewScrollPositionBottom
6 } UITableViewScrollPosition;```
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市骤肛,隨后出現(xiàn)的幾起案子纳本,更是在濱河造成了極大的恐慌,老刑警劉巖腋颠,帶你破解...
    沈念sama閱讀 222,590評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件繁成,死亡現(xiàn)場離奇詭異,居然都是意外死亡淑玫,警方通過查閱死者的電腦和手機巾腕,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,157評論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來絮蒿,“玉大人尊搬,你說我怎么就攤上這事⊥晾裕” “怎么了佛寿?”我有些...
    開封第一講書人閱讀 169,301評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長但壮。 經(jīng)常有香客問我冀泻,道長,這世上最難降的妖魔是什么蜡饵? 我笑而不...
    開封第一講書人閱讀 60,078評論 1 300
  • 正文 為了忘掉前任弹渔,我火速辦了婚禮,結(jié)果婚禮上验残,老公的妹妹穿的比我還像新娘捞附。我一直安慰自己,他們只是感情好您没,可當(dāng)我...
    茶點故事閱讀 69,082評論 6 398
  • 文/花漫 我一把揭開白布鸟召。 她就那樣靜靜地躺著,像睡著了一般氨鹏。 火紅的嫁衣襯著肌膚如雪欧募。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,682評論 1 312
  • 那天仆抵,我揣著相機與錄音跟继,去河邊找鬼种冬。 笑死,一個胖子當(dāng)著我的面吹牛舔糖,可吹牛的內(nèi)容都是我干的娱两。 我是一名探鬼主播,決...
    沈念sama閱讀 41,155評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼金吗,長吁一口氣:“原來是場噩夢啊……” “哼十兢!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起摇庙,我...
    開封第一講書人閱讀 40,098評論 0 277
  • 序言:老撾萬榮一對情侶失蹤旱物,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后卫袒,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體宵呛,經(jīng)...
    沈念sama閱讀 46,638評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,701評論 3 342
  • 正文 我和宋清朗相戀三年夕凝,在試婚紗的時候發(fā)現(xiàn)自己被綠了宝穗。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,852評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡码秉,死狀恐怖讽营,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情泡徙,我是刑警寧澤橱鹏,帶...
    沈念sama閱讀 36,520評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站堪藐,受9級特大地震影響莉兰,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜礁竞,卻給世界環(huán)境...
    茶點故事閱讀 42,181評論 3 335
  • 文/蒙蒙 一糖荒、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧模捂,春花似錦捶朵、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,674評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至岖食,卻和暖如春红碑,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,788評論 1 274
  • 我被黑心中介騙來泰國打工析珊, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留羡鸥,地道東北人。 一個月前我還...
    沈念sama閱讀 49,279評論 3 379
  • 正文 我出身青樓忠寻,卻偏偏與公主長得像惧浴,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子奕剃,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,851評論 2 361

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