日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[9]UITableView表视图1

發布時間:2024/4/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [9]UITableView表视图1 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

UITableView表視圖

UITableViewDataSource,UITableViewDelegate UITabelView表視圖的倆個協議,
UITableViewDataSource這個協議中的倆個必須執行的方法

@required //顯示多少行 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; //每行顯示的內容 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

點擊選中單元格的時候執行的方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {NSLog(@"%@",indexPath); }

設置頭部區域的高度 注意:在自定義頭部文本的時候 默認的不用寫 但是頭部區域的高度一定要寫 正確使用這個的高度顯示 不然不會出現頭部文本

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {return 60; }

給分區頭部自定義視圖

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {UILabel *footLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 60)];footLabel.text = @"食物";footLabel.font = [UIFont boldSystemFontOfSize:30];footLabel.textAlignment = NSTextAlignmentCenter;UILabel *bookLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 0)];bookLabel.text = @"四大名族";bookLabel.font = [UIFont boldSystemFontOfSize:30];bookLabel.textAlignment = NSTextAlignmentCenter;UILabel *gameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 60)];gameLabel.text = @"游戲";gameLabel.font = [UIFont boldSystemFontOfSize:30];gameLabel.textAlignment = NSTextAlignmentCenter;switch (section) {case 0:return footLabel;break; case 1:return bookLabel;break;case 2:return gameLabel;break; default:break;}return nil; }

設置分區頭部顯示文本

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { switch (section) {case 0:return @"食物";break;case 1:return @"四大名族";break;case 2:return @"游戲";break;default:break;}return nil; }

//設置表視圖的分區個數

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 3; }

小技巧 :何時需要重寫loadView方法???
1.RootViewController繼承自UIViewController,繼承了loadView方法,可以給自定的視圖指定新視圖
2.UIViewController 通過loadView方法創建的視圖是一個空視圖,如果我們的需求不是空視圖,那么就需要我們自己創建一個視圖,指定給self.view,此時需要重寫loadView方法

轉載于:https://www.cnblogs.com/ianhao/p/4471658.html

總結

以上是生活随笔為你收集整理的[9]UITableView表视图1的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。