国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

ios基于UITableViewController實現列表

2020-07-26 02:57:29
字體:
來源:轉載
供稿:網友

實現效果圖如下:

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 = @"四川青川縣今晨發生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將可分屏多任務";   n3.count = 3278;   n3.imageName = @"hqg";      News *n4 = [[News alloc]init];   n4.title = @"JAVA語言估計下月進入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 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 策勒县| 富民县| 交口县| 宜昌市| 无极县| 铁力市| 湛江市| 兴仁县| 丰镇市| 武强县| 广昌县| 山阳县| 读书| 彩票| 卢湾区| 沧源| 衡南县| 兴国县| 河源市| 辽阳县| 长丰县| 磴口县| 佛冈县| 东辽县| 鹤庆县| 长岭县| 龙海市| 彭泽县| 榆树市| 淳安县| 满城县| 盐源县| 仁化县| 阿城市| 博湖县| 淮阳县| 拉孜县| 收藏| 疏勒县| 镇远县| 饶平县|