ios基于UITableViewController實現(xiàn)列表
更新時間:2017年01月24日 10:11:40 作者:chenzheng8975
這篇文章主要介紹了ios基于UITableViewController實現(xiàn)列表的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
實現(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將可分屏多任務";
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
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Objective-C與Swift之間的互相調(diào)用和跳轉
這篇文章主要給大家介紹了關于Objective-C與Swift之間的互相調(diào)用和跳轉的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-05-05
iOS8調(diào)用相機報警告Snapshotting a view的解決方法
這篇文章主要介紹了iOS8調(diào)用相機報警告Snapshotting a view……的解決方法 ,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11
iOS AVCaptureSession實現(xiàn)視頻錄制功能
這篇文章主要為大家詳細介紹了iOS AVCaptureSession實現(xiàn)視頻錄制功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05
IOS開發(fā)代碼分享之設置UISearchBar的背景顏色
在項目開發(fā)中,我們經(jīng)常要用到UISearchBar,在網(wǎng)上看到了很多關于去除掉他背景色的方法,都已經(jīng)失效了,今天來分享一個正常使用的方法,希望能幫到大家2014-09-09
IOS開發(fā)之判斷兩個數(shù)組中數(shù)據(jù)是否相同實例詳解
這篇文章主要介紹了IOS開發(fā)之判斷兩個數(shù)組中數(shù)據(jù)是否相同實例詳解的相關資料,需要的朋友可以參考下2017-02-02

