iOS 自定义UITableViewCell
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
#import "AppDelegate.h"
#import "AViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; AViewController *root = [AViewController new];
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:root]; self.window.rootViewController = navi;
[self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h> @interface AViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
// 呈现数据源的控件
UITableView *_tableView; // 数据源
NSArray *datas;
}
@end
#import "AViewController.h"
#import "CumstomCell.h"//导入自定义的cell @implementation AViewController -(void)loadView
{
[super loadView]; // 不分组的plain样式
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(, , , ) style:UITableViewStylePlain];
// 数据源代理
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView];
} - (void)viewDidLoad {
[super viewDidLoad]; NSString *str = @"A,B,C,D,E,F,G,H,I,J,K,L,M,N";
datas = [str componentsSeparatedByString:@","];
} #pragma mark -数据源配置-
// 配置tablview显示多少行数据
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return datas.count;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 120.0f;
} // 每个cell显示什么内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *indentity = @"cell";
//使用自定义的cell
CumstomCell *cell = [_tableView dequeueReusableCellWithIdentifier:indentity];
if (cell == nil) {
cell=[[CumstomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentity];
} //NSLog(@"%d",indexPath.row);
//NSString *t = [datas objectAtIndex:indexPath.row]; //cell.textLabel.text = t;
cell.imgView1.image = [UIImage imageNamed:@"123.jpg"];
cell.imgView2.image = [UIImage imageNamed:@"123.jpg"];
cell.imgView3.image = [UIImage imageNamed:@"123.jpg"]; return cell;
} @end
#import <UIKit/UIKit.h> @interface CumstomCell : UITableViewCell @property(nonatomic,strong)UIImageView *imgView1;
@property(nonatomic,strong)UIImageView *imgView2;
@property(nonatomic,strong)UIImageView *imgView3; @end
#import "CumstomCell.h" @implementation CumstomCell
@synthesize imgView1=_imgView1;
@synthesize imgView2=_imgView2;
@synthesize imgView3=_imgView3; -(void)dealloc{ /*
[_imgView1 release];
[_imgView2 release];
[_imgView3 release];
[super dealloc];
*/ _imgView1 = nil;
_imgView2 = nil;
_imgView3 = nil;
}
/**
* 重写该方法
*/
-(UITableViewCell *)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
//self.imgView1.backgroundColor = [UIColor redColor];
[self.contentView addSubview:self.imgView1]; self.imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(++, , , )];
//self.imgView2.backgroundColor = [UIColor redColor];
[self.contentView addSubview:self.imgView2]; self.imgView3 = [[UIImageView alloc] initWithFrame:CGRectMake(+*+*, , , )];
//self.imgView3.backgroundColor = [UIColor redColor];
[self.contentView addSubview:self.imgView3]; } return self;
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end
iOS 自定义UITableViewCell的更多相关文章
- ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局
本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...
- 【转】iOS 通过xib自定义UITableViewCell【原创】
原文网址:http://blog.it985.com/9683.html 在使用tableView的时候,如果cell的布局过于复杂,通过代码搭建的话不够直观.并且要不停的调整位置,字体什么的.这时, ...
- iOS学习之自定义UItableViewCell
在项目开发中,大部分情况下我们都需要自定义UITableViewCell, 今天就重点整理一下目前自己已经学过的自定义Cell的一些注意事项; 分步骤来写吧: 1.将自定义的Cell定义为属性; 2. ...
- IOS开发---菜鸟学习之路--(七)-自定义UITableViewCell
本篇将介绍如何自定义 UITableViewCell 首先选择新建文件 可以直接使用快捷键 COMMAND+n打开新建页面,然后选Objective-C class 然后选择继承之UITableVie ...
- 通过xib自定义UITableViewCell
通过xib自定义UITableViewCell 一.新建iOS Application工程,选择Single View Application,不要选中Use Storyboard.假设指定的是pro ...
- 114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果)
关键操作: 效果如下: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UITableViewCo ...
- IOS中UITableViewCell使用详解
IOS中UITableViewCell使用详解 - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(N ...
- iOS开发UITableViewCell的选中时的颜色设置(转)
iOS开发UITableViewCell的选中时的颜色设置 1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyle ...
随机推荐
- jpush极光推送知识点总结
1.jpushClient.sendPush(pushpayLoad):是发送推送的主要方法 2.pushpayload是具体推送消息.推送对象范围的封装 3.jpushClient.sendPush ...
- JAVA分支语句例题
1.输入年份判断是闰年还是平年? System.out.println("请输入年份:"); Scanner sc=new Scanner(System.in); String s ...
- 关于C和C++动态链接库的几个问题
问题: 1.写一段C++程序,编译成动态链接库后,C程序怎么访问? 2.写一段C程序,编译成动态链接库后,C++程序怎么访问? 3.写一个类,编译成动态链接库后,里面的public变量能否访问? 对于 ...
- Myeclipse配置 项目编码格式
修改MyEclipse 工作空间的编码 修改之后,在该工作空间下创建的任何项目,编码都是UTF-8,既,该项目下所有文件都是utf-8 格式,工作空间影响项目,项目影响文件 General --> ...
- 已禁用对分布式事务管理器(MSDTC)的网络访问。请使用组件服务管理工具启用 DTC 以便在 MSDTC 安全配置中进行网络访问。
今天写ASP.NET程序,在网页后台的c#代码里写了个事务,事务内部对一张表进行批量插入,对另外一张表进行查询与批量插入. 结果第二张表查询后foreach迭代操作时报错:已禁用对分布式事务管理器(M ...
- python 之 推导式
推导式 : 英文 comprehension 支持推导式的有列表list 字典dict 集合set 注意元组没有 推导式,如果你那样去写,他会变成一个generator生 ...
- php日期时间函数 整理
设定系统默认时区 date_default_timezone_get() $tz='America/Los_Angeles'; 返回系统默认时区 date_default_timezone_set($ ...
- 【Android测试】【随笔】与 “美丽说” 测试同事交流
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5405432.html 分享者简介 雪晗,3年+测试经验,现 ...
- LTRIM(str):返回 字符串str的前导(左边)空格字符去掉。
SELECT ' 11' res SELECT LTRIM(' 11') resL 运行结果:
- Ubuntu 设置Vim tab为四个空格
使用root权限打开 /etc/vim/vimrc 添加下列配置 set tabstop= set softtabstop= set shiftwidth= set noexpandtab set n ...