[iOS]TableView 相關(guān)屬性和方法

1愈诚、初始化一個(gè)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、配置一個(gè)TableView

1)返回這個(gè)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, //無(wú)分隔線
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)注冊(cè)一個(gè)包含指定標(biāo)示符TableView的Cell的nib對(duì)象

1 - (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier //兩個(gè)參數(shù)不能是nil
2 //Available in iOS 5.0 and later.```
2)注冊(cè)一個(gè)類用來(lái)創(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重要提示:使用這個(gè)方法之前必須是使用了registerNib:forCellReuseIdentifier: 或者 registerClass:forCellReuseIdentifier:方法注冊(cè)了Cell

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

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

4具则、訪問(wèn)表頭和表尾的視圖

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

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

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section```
footer通過(guò)下面兩個(gè)
  • (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

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

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

1 - (void)registerNib:(UINib *)nib forHeaderFooterViewReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.```
2)注冊(cè)一個(gè)類,用來(lái)創(chuàng)建新的包含表頭或表尾的表視圖

1 - (void)registerClass:(Class)aClass forHeaderFooterViewReuseIdentifier:(NSString *)identifier
2 //Available in iOS 6.0 and later.```
3)返回一個(gè)指定標(biāo)識(shí)符的可重用的附帶表頭表尾的視圖

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博肋、訪問(wèn)Cell和Section

1)返回指定indexPath的Cell

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

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

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

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

1 - (NSArray *)visibleCells```
6)返回可見(jiàn)表格行的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蜂厅、滾動(dòng)TableView

1)滾動(dòng)到指定的位置

1 - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated
1 typedef enum {
2 UITableViewScrollPositionNone,
3 UITableViewScrollPositionTop,
4 UITableViewScrollPositionMiddle,
5 UITableViewScrollPositionBottom
6 } UITableViewScrollPosition;

轉(zhuǎn)載http://www.reibang.com/p/1ddec29b83a0 感謝作者
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市膊畴,隨后出現(xiàn)的幾起案子掘猿,更是在濱河造成了極大的恐慌,老刑警劉巖唇跨,帶你破解...
    沈念sama閱讀 222,183評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件稠通,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡买猖,警方通過(guò)查閱死者的電腦和手機(jī)改橘,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)玉控,“玉大人飞主,你說(shuō)我怎么就攤上這事「吲担” “怎么了碌识?”我有些...
    開(kāi)封第一講書(shū)人閱讀 168,766評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)虱而。 經(jīng)常有香客問(wèn)我筏餐,道長(zhǎng),這世上最難降的妖魔是什么牡拇? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,854評(píng)論 1 299
  • 正文 為了忘掉前任胖烛,我火速辦了婚禮,結(jié)果婚禮上诅迷,老公的妹妹穿的比我還像新娘。我一直安慰自己众旗,他們只是感情好罢杉,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,871評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著贡歧,像睡著了一般滩租。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上利朵,一...
    開(kāi)封第一講書(shū)人閱讀 52,457評(píng)論 1 311
  • 那天律想,我揣著相機(jī)與錄音,去河邊找鬼绍弟。 笑死技即,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的樟遣。 我是一名探鬼主播而叼,決...
    沈念sama閱讀 40,999評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼身笤,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了葵陵?” 一聲冷哼從身側(cè)響起液荸,我...
    開(kāi)封第一講書(shū)人閱讀 39,914評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎脱篙,沒(méi)想到半個(gè)月后娇钱,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,465評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡绊困,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,543評(píng)論 3 342
  • 正文 我和宋清朗相戀三年文搂,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片考抄。...
    茶點(diǎn)故事閱讀 40,675評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡细疚,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出川梅,到底是詐尸還是另有隱情疯兼,我是刑警寧澤,帶...
    沈念sama閱讀 36,354評(píng)論 5 351
  • 正文 年R本政府宣布贫途,位于F島的核電站吧彪,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏丢早。R本人自食惡果不足惜姨裸,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,029評(píng)論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望怨酝。 院中可真熱鬧傀缩,春花似錦、人聲如沸农猬。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,514評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)斤葱。三九已至慷垮,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間揍堕,已是汗流浹背料身。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,616評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留衩茸,地道東北人芹血。 一個(gè)月前我還...
    沈念sama閱讀 49,091評(píng)論 3 378
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親祟牲。 傳聞我的和親對(duì)象是個(gè)殘疾皇子隙畜,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,685評(píng)論 2 360

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