ios基于UITableViewController實(shí)現(xiàn)列表
實(shí)現(xiàn)效果圖如下:
News.h
#import <Foundation/Foundation.h> @interface News : NSObject @property (nonatomic, strong) NSString *title; @property (nonatomic) NSUInteger count; @property (nonatomic, strong) NSString *imageName; + (NSArray *)demoData; @end<strong> </strong>
News.m
#import "News.h" @implementation News + (NSArray *)demoData { News *n1 = [[News alloc]init]; n1.title = @"四川青川縣今晨發(fā)生4.8地震"; n1.count = 2175; n1.imageName = @"hqg"; News *n2 = [[News alloc]init]; n2.title = @"3名奪刀少年遭多所高校\"哄搶\""; n2.count = 987; n2.imageName = @"hqg"; News *n3 = [[News alloc]init]; n3.title = @"代碼顯示Eclipse將可分屏多任務(wù)"; n3.count = 3278; n3.imageName = @"hqg"; News *n4 = [[News alloc]init]; n4.title = @"JAVA語(yǔ)言估計(jì)下月進(jìn)入TIOBE前20名"; n4.count = 1462; n4.imageName = @"hqg"; return @[n1, n2, n3, n4]; }@end
NewsCell.h
#import <UIKit/UIKit.h> @interface NewsCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIImageView *newsImageView; @property (weak, nonatomic) IBOutlet UILabel *titleLabel; @property (weak, nonatomic) IBOutlet UILabel *countLabel; @end
NewsCell.m
#import "NewsCell.h" @implementation NewsCell - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end
NewsCell.xib
NewsTableViewController.h
#import <UIKit/UIKit.h> @interface NewsTableViewController : UITableViewController @property (nonatomic, strong) NSArray *news; @end
NewsTableViewController.m
#import "NewsTableViewController.h" #import "News.h" #import "NewsCell.h" @interface NewsTableViewController () @end @implementation NewsTableViewController static NSString *cellIdentifier = @"MyNewsCell"; - (void)viewDidLoad { [super viewDidLoad]; self.news = [News demoData]; self.title = @"騰訊新聞"; UINib *nib = [UINib nibWithNibName:@"NewsCell" bundle:nil]; [self.tableView registerNib:nib forCellReuseIdentifier:cellIdentifier]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.news.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 86; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { News *news = self.news[indexPath.row]; NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; cell.titleLabel.text = news.title; cell.countLabel.text = [NSString stringWithFormat:@"%ld", news.count]; cell.newsImageView.image = [UIImage imageNamed:news.imageName]; return cell; } @end
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- IOS實(shí)現(xiàn)展開(kāi)二級(jí)列表效果
- IOS展開(kāi)三級(jí)列表效果示例
- iOS多級(jí)列表實(shí)現(xiàn)代碼
- IOS實(shí)現(xiàn)簡(jiǎn)易版的QQ下拉列表
- iOS開(kāi)發(fā)之在列表上方添加水印的方法
- iOS 標(biāo)簽Tag列表的實(shí)現(xiàn)代碼
- iOS實(shí)現(xiàn)列表折疊效果
- iOS列表上拉(平滑加載數(shù)據(jù))自動(dòng)加載數(shù)據(jù)的問(wèn)題解決
- iOS實(shí)現(xiàn)從通訊錄中選擇聯(lián)系人
- iOS實(shí)現(xiàn)聯(lián)系人列表功能
相關(guān)文章
簡(jiǎn)單談?wù)凜ore Animation 動(dòng)畫(huà)效果
下面小編就為大家?guī)?lái)一篇簡(jiǎn)單談?wù)凜ore Animation 動(dòng)畫(huà)效果。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06iOS NSThread和NSOperation的基本使用詳解
下面小編就為大家分享一篇iOS NSThread和NSOperation的基本使用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01ios12中遇到的帶input彈窗的錯(cuò)位問(wèn)題的解決方法
這篇文章主要介紹了ios12中遇到的帶input彈窗的錯(cuò)位問(wèn)題的解決方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-05-05iOS支付寶、微信、銀聯(lián)支付集成封裝調(diào)用(上)
本篇文章給大家分享了iOS支付寶、微信、銀聯(lián)支付集成封裝調(diào)用的相關(guān)代碼和實(shí)例,有興趣的朋友學(xué)習(xí)下。2018-04-04iOS8調(diào)用相機(jī)報(bào)警告Snapshotting a view的解決方法
這篇文章主要介紹了iOS8調(diào)用相機(jī)報(bào)警告Snapshotting a view……的解決方法 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11iOS UITableView 與 UITableViewController實(shí)例詳解
這篇文章主要介紹了iOS UITableView 與 UITableViewController實(shí)例詳解的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-09-09iOS 圖片上傳使用base64或者二進(jìn)制流上傳頭像功能
這篇文章主要介紹了iOS 圖片上傳使用base64或者二進(jìn)制流上傳頭像功能,需要的朋友可以參考下2017-09-09