IOS自定义表格视图
来源:互联网 发布:mac抹除磁盘选什么格式 编辑:程序博客网 时间:2024/05/22 14:39
RecommendViewController.m文件
import"RecommendViewController.h"
#import"CustomTableView.h"
@interfaceRecommendViewController ()
{
NSMutableArray * _dataSource;
NSMutableArray * _data;
NSMutableArray * _dataImages;
}
- (void)initData;
@end
@implementation RecommendViewController
- (void)dealloc
{
[_dataSourcerelease];
[_dataImagesrelease];
[superdealloc];
}
- (void)viewDidLoad {
[superviewDidLoad];
[selfinitData];
}
- (void)initData
{
self.navigationItem.title =@"推荐";
self.view.backgroundColor = [UIColorwhiteColor];
//从plist中读取数据
_dataSource = [[NSMutableArrayalloc] initWithContentsOfFile:[[NSBundlemainBundle] pathForAuxiliaryExecutable:@"DetailInfomation.plist"]];
_dataImages = [[NSMutableArrayalloc] initWithObjects:@"dog1.png",@"dog2.png",@"dog3.png",@"dog4.png",nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellID =@"chongyong";
CustomTableView * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[CustomTableViewalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellID];
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
}
cell.leftImageView.image = [UIImageimageNamed:_dataImages[indexPath.row]];
cell.topLable.text =_dataSource[indexPath.row][@"name"];
cell.addressLabel.text =_dataSource[indexPath.row][@"address"];
cell.phoneLabel.text =_dataSource[indexPath.row][@"phone"];
cell.stateLabel.text =_dataSource[indexPath.row][@"classify"];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{//单元格的组数
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{//单元格的行数
return _dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ //单元格的高度
return 100;
}
@end
自定义单元格视图
CustomTableView.h文件
#import <UIKit/UIKit.h>
@interface CustomTableView :UITableViewCell
@property (nonatomic,retain)UIImageView * leftImageView;
@property (nonatomic,retain)UILabel * topLable;
@property (nonatomic,retain)UILabel * phoneLabel;
@property (nonatomic,retain)UILabel * addressLabel;
@property (nonatomic,retain)UILabel * stateLabel;
@end
CustomTableView.m文件
#import"CustomTableView.h"
@implementation CustomTableView
- (void)dealloc
{
[_leftImageViewrelease];
[_topLablerelease];
[_addressLabelrelease];
[_phoneLabelrelease];
[_stateLabelrelease];
[superdealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [superinitWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_leftImageView = [[UIImageViewalloc] initWithFrame:CGRectMake(5,10, 110,90)];
_leftImageView.layer.cornerRadius =7;
_leftImageView.layer.masksToBounds =YES;
[self.contentViewaddSubview:_leftImageView];
_topLable = [[UILabelalloc] initWithFrame:CGRectMake(125,11, 120,25)];
_topLable.font = [UIFontboldSystemFontOfSize:19];
_topLable.textColor = [UIColororangeColor];
[self.contentViewaddSubview:_topLable];
_addressLabel = [[UILabelalloc] initWithFrame:CGRectMake(125,40, 140,21)];
_addressLabel.font = [UIFontsystemFontOfSize:15];
_addressLabel.textColor = [UIColorblackColor];
[self.contentViewaddSubview:_addressLabel];
_phoneLabel = [[UILabelalloc] initWithFrame:CGRectMake(125,70, 120,20)];
_phoneLabel.font = [UIFontsystemFontOfSize:14];
_phoneLabel.textColor = [UIColorgrayColor];
[self.contentViewaddSubview:_phoneLabel];
_stateLabel = [[UILabelalloc] initWithFrame:CGRectMake(270,16, 90,20)];
_stateLabel.font = [UIFontboldSystemFontOfSize:18];
_stateLabel.textColor = [UIColorredColor];
[self.contentViewaddSubview:_stateLabel];
}
return self;
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[supersetSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
- IOS自定义表格视图
- iOS表格视图 GMGridView
- iOS表格视图 GMGridView
- iOS开源:表格视图GMGridView
- IOS - 自定义表格(UITableView)
- IOS - 自定义表格(UITableView)
- iOS 自定义表格
- ios中自定义视图
- iOS开发-------模拟团购网站(UITableView 表格视图)以及自定义cell
- iOS第13章 表格视图
- IOS UITableView 表格视图的绝大部分方法
- iOS - 创建表格类视图WBDataGridView
- iOS开发系列课程(10) --- 表格视图
- iOS 自定义模态视图
- IOS--UI--LessonCustumView 自定义视图
- IOS开发 - 04.自定义视图
- iOS中自定义视图控件
- iOS开发 UI 自定义视图
- oracle的启动关闭
- Ogre的内存分配策略
- IntentFilter
- Struts2中的ModelDriven机制及其运用
- Jsoup网页抓取技术
- IOS自定义表格视图
- java---Spring
- 面试题4——求一个int型整数的两种递减数之和
- 我的java学习笔记(5)关于对象构造
- [****Camp Day 1]C. Control Point(乱搞)
- 安装Sublime Text 3插件的方法
- OJ 1185 特殊排序
- 黑马程序员——Java基础知识——面向对象(二)
- Hadoop学习笔记之Hadoop简介