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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UITableView的使用及代理方法

發(fā)布時間:2023/12/6 编程问答 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UITableView的使用及代理方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在App開放中我們經(jīng)常會使用到UITabbleView,常用于數(shù)據(jù)展示。那么使用時不得不引入兩個代理方法<UITableViewDataSource,UITableViewDelegate>。 下面我們來簡單的創(chuàng)建一個TableView并介紹下其基本屬性。 @property (nonatomic,strong) UITableView * myTable; //聲明對象 建議使用懶加載的方式創(chuàng)建,可以節(jié)省內(nèi)存,然后再外部請求到數(shù)據(jù)后用.語法調(diào)用。

- (UITableView *)myTable{ if (!_myTable) { _myTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HEIGHT-64-44) style:UITableViewStylePlain]; //初始化對象并設(shè)定大小和風(fēng)格樣式 _myTable.delegate = self; _myTable.dataSource = self; //設(shè)置代理 _myTable.showsHorizontalScrollIndicator = NO; //不顯示水平滾動條 _myTable.showsVerticalScrollIndicator = NO; //不顯示豎直滾動條 _myTable.bounces = NO; //關(guān)閉彈性效果 } return _myTable; }

我們要在UITableView上展示數(shù)據(jù),所以要有一個數(shù)據(jù)源,同理數(shù)據(jù)源也采用懶加載的方式。 @property (nonatomic,strong) NSMutableArray * dataSorce;

- (NSMutableArray *)dataSorce{ if (!_dataSorce) { _dataSorce = [[NSMutableArray alloc]init]; } return _dataSorce; }

下面開始設(shè)置代理方法:


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataSorce.count; //返回cell的個數(shù) }


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 40; //返回cell的高度 }


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString * string = @"patrcell"; PartCell * cell = [tableView dequeueReusableCellWithIdentifier:string]; if (!cell) { cell = [[PartCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; return cell; //cell的復(fù)用及自定義cell的樣式 }


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ }

轉(zhuǎn)載于:https://juejin.im/post/5a3207155188253da72e76af

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的UITableView的使用及代理方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。