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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

UITableView的使用及代理方法

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

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

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

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

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

下面開始設置代理方法:


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


- (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的復用及自定義cell的樣式 }


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

轉載于:https://juejin.im/post/5a3207155188253da72e76af

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

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

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