ios基于UITableViewController实现列表

 更新时间:2017年01月24日 10:11:40   作者:chenzheng8975  
这篇文章主要介绍了ios基于UITableViewController实现列表的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

实现效果图如下:

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 

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

相关文章

  • iOS如何获取当前日期前后N天的时间示例代码

    iOS如何获取当前日期前后N天的时间示例代码

    这篇文章主要给大家介绍了关于iOS如何获取当前日期前后N天的时间的相关资料,文中通过示例代码介绍的非常详细,对各位iOS开发者们具有一定的参考学习价值,需要的朋友们下面随着小编来一起看看吧。
    2017-11-11
  • iOS弹幕组件LNDanmakuMaster的具体使用

    iOS弹幕组件LNDanmakuMaster的具体使用

    这篇文章主要介绍了iOS弹幕组件LNDanmakuMaster的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-02-02
  • Objective-C与Swift之间的互相调用和跳转

    Objective-C与Swift之间的互相调用和跳转

    这篇文章主要给大家介绍了关于Objective-C与Swift之间的互相调用和跳转的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-05-05
  • iOS8调用相机报警告Snapshotting a view的解决方法

    iOS8调用相机报警告Snapshotting a view的解决方法

    这篇文章主要介绍了iOS8调用相机报警告Snapshotting a view……的解决方法 ,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-11-11
  • IOS 指纹识别两种方式详解及实例

    IOS 指纹识别两种方式详解及实例

    这篇文章主要介绍了IOS 指纹识别两种方式详解及实例的相关资料,需要的朋友可以参考下
    2017-06-06
  • iOS图片界面翻页切换效果

    iOS图片界面翻页切换效果

    这篇文章主要为大家详细介绍了iOS图片界面翻页切换效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-11-11
  • iOS AVCaptureSession实现视频录制功能

    iOS AVCaptureSession实现视频录制功能

    这篇文章主要为大家详细介绍了iOS AVCaptureSession实现视频录制功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05
  • IOS开发代码分享之设置UISearchBar的背景颜色

    IOS开发代码分享之设置UISearchBar的背景颜色

    在项目开发中,我们经常要用到UISearchBar,在网上看到了很多关于去除掉他背景色的方法,都已经失效了,今天来分享一个正常使用的方法,希望能帮到大家
    2014-09-09
  • iOS开发之微信聊天工具栏的封装

    iOS开发之微信聊天工具栏的封装

    这篇文章主要为大家详细介绍了iOS开发之微信聊天工具栏的封装,针对聊天工具条进行封装,感兴趣的小伙伴们可以参考一下
    2016-02-02
  • IOS开发之判断两个数组中数据是否相同实例详解

    IOS开发之判断两个数组中数据是否相同实例详解

    这篇文章主要介绍了IOS开发之判断两个数组中数据是否相同实例详解的相关资料,需要的朋友可以参考下
    2017-02-02

最新评论