资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

ios基于UITableViewController实现列表

实现效果图如下:

十多年的诸暨网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网整合营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整诸暨建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“诸暨网站设计”,“诸暨网站推广”以来,每个客户项目都认真落实执行。

ios基于UITableViewController实现列表

News.h

#import  
 
@interface News : NSObject 
 
@property (nonatomic, strong) NSString *title; 
@property (nonatomic) NSUInteger count; 
@property (nonatomic, strong) NSString *imageName; 
+ (NSArray *)demoData; 
@end 
 

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  
 
@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

ios基于UITableViewController实现列表

NewsTableViewController.h

#import  
 
@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 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


文章标题:ios基于UITableViewController实现列表
转载来于:http://cdkjz.cn/article/giiois.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220