实例讲解iOS应用开发中使用UITableView创建自定义表格

2020-01-14 19:52:03王冬梅
实例讲解iOS应用开发中使用UITableView创建自定义表格

2.数据源,在interface中声明

复制代码
NSMutableArray *news_MArray;// 新闻内容数据源
    新建一个model类,命名为"newsModel",存放每一项数据

 

    newsModel.h如下,.m中没有添加其他代码,如果需要拷贝,可以重载copyWithZone方法,
#import <Foundation/Foundation.h>
 
typedef NS_ENUM(NSInteger, NEWSReportType){
    NEWSReportOrdinary, // 普通新闻
    NEWSReportExclusive,// 独家新闻
    NEWSReportSpecial,  // 专题新闻
};
 
@interface newsModel : NSObject
 
@property (nonatomic, copy)NSString *       news_image;     //图片
@property (nonatomic, copy)NSString *       news_title;     //标题
@property (nonatomic, copy)NSString *       news_summary;   //摘要
@property (nonatomic, assign)NSInteger      news_replyNo;   //跟帖数量
@property (nonatomic, assign)NEWSReportType reportType;     //报道类型
 
 
@end


    在viewDidLoad方法中
复制代码
news_MArray = [[NSMutableArray alloc] init];
for(NSInteger index =0; index<10; index++){
    newsModel *model    = [[newsModel alloc] init];
    model.news_image    = [NSString stringWithFormat:@"%d.jpg",index+1];
    model.news_title    = @"曾在月光之下望烟花";
    model.news_summary  = @"曾共看夕阳渐降下 我怎么舍得去放下 要怎么舍得去放下";
    model.news_replyNo  = index+196;
    model.reportType    = index%3;
     
    [news_MArray addObject:model];
}
3.行数
复制代码
// 每个分区行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section