UITableViewCell的简单应用-瀑布形相册
2014-06-20 19:43
92 查看
@interface MainViewController :
UIViewController
@property (nonatomic,
retain)UITableView *table1;
@property (nonatomic,
retain)UITableView *table2;
@property (nonatomic,
retain)UITableView *table3;
@end
@interface
MainViewController ()<UITableViewDataSource,
UITableViewDelegate>
@property (nonatomic,
retain)NSMutableArray *array;
@property (nonatomic,
retain)NSMutableArray *array1;
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.array = [NSMutableArray
array];
for (int i =
0; i < 22; i++) {
UIImage *image = [UIImage
imageNamed:[NSString
stringWithFormat:@"%d.jpg",i +
1]];
[self.array
addObject:image];
}
self.array1 = [NSMutableArray
array];
for (int i =
100; i < 122; i++) {
UIImage *image = [UIImage
imageNamed:[NSString
stringWithFormat:@"%d.jpg",i]];
[self.array1
addObject:image];
}
self.table1 = [[UITableView
alloc] initWithFrame:CGRectMake(0,
64,
100, 416)
style:(UITableViewStylePlain)];
self.table1.delegate =
self;
self.table1.dataSource =
self;
[self.view
addSubview:self.table1];
[_table1
release];
self.table2 = [[UITableView
alloc] initWithFrame:CGRectMake(110,
64,
100, 416)
style:(UITableViewStylePlain)];
self.table2.delegate =
self;
self.table2.dataSource =
self;
[self.view
addSubview:self.table2];
[_table2
release];
self.table3 = [[UITableView
alloc] initWithFrame:CGRectMake(220,
64,
100, 416)
style:(UITableViewStylePlain)];
self.table3.delegate =
self;
self.table3.dataSource =
self;
[self.view
addSubview:self.table3];
[_table3
release];
}
return
self;
}
- (void)viewDidLoad
{
[super
viewDidLoad];
// Do any additional setup after loading the view.
[self
setAutomaticallyAdjustsScrollViewInsets:NO];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView ==
self.table1) {
self.table2.contentOffset = scrollView.contentOffset;
self.table3.contentOffset = scrollView.contentOffset;
}
else if (scrollView ==
self.table2){
self.table1.contentOffset = scrollView.contentOffset;
self.table3.contentOffset = scrollView.contentOffset;
}
else{
self.table1.contentOffset = scrollView.contentOffset;
self.table2.contentOffset = scrollView.contentOffset;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.table2) {
return self.array1.count;
}else {
return self.array.count;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
UIImage *image = [self.array
objectAtIndex:indexPath.row];
return image.size.height *
100/ image.size.width;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (tableView == self.table2) {
NSString *str = @"kzss1";
MyCell *cell = [tableView
dequeueReusableCellWithIdentifier:str];
if (nil == cell) {
cell = [[[MyCell
alloc] initWithStyle:(UITableViewCellStyleSubtitle)
reuseIdentifier:str] autorelease];
}
UIImage *image = [self.array1
objectAtIndex:indexPath.row];
cell.myImageView.image = image;
return cell;
}
else {
NSString *str = @"kzss";
MyCell *cell = [tableView
dequeueReusableCellWithIdentifier:str];
if (nil == cell) {
cell = [[[MyCell
alloc] initWithStyle:(UITableViewCellStyleSubtitle)
reuseIdentifier:str] autorelease];
}
UIImage *image = [self.array
objectAtIndex:indexPath.row];
cell.myImageView.image = image;
return cell;
}
}
- (void)didReceiveMemoryWarning
{
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@interface MyCell :
UITableViewCell
@property (nonatomic ,retain)
UIImageView *myImageView;
@end
@implementation MyCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString
*)reuseIdentifier
{
self = [super
initWithStyle:style
reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.myImageView = [[UIImageView
alloc] init];
[self.contentView
addSubview:self.myImageView];
[self.myImageView
release];
}
return
self;
}
- (void)layoutSubviews
{
[super
layoutSubviews];
// self.myImageView.frame = CGRectMake(0, 0,self.frame.size.width/3, self.frame.size.height);
self.myImageView.frame =
self.contentView.bounds;
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super
setSelected:selected
animated:animated];
// Configure the view for the selected state
}
@end
UIViewController
@property (nonatomic,
retain)UITableView *table1;
@property (nonatomic,
retain)UITableView *table2;
@property (nonatomic,
retain)UITableView *table3;
@end
@interface
MainViewController ()<UITableViewDataSource,
UITableViewDelegate>
@property (nonatomic,
retain)NSMutableArray *array;
@property (nonatomic,
retain)NSMutableArray *array1;
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.array = [NSMutableArray
array];
for (int i =
0; i < 22; i++) {
UIImage *image = [UIImage
imageNamed:[NSString
stringWithFormat:@"%d.jpg",i +
1]];
[self.array
addObject:image];
}
self.array1 = [NSMutableArray
array];
for (int i =
100; i < 122; i++) {
UIImage *image = [UIImage
imageNamed:[NSString
stringWithFormat:@"%d.jpg",i]];
[self.array1
addObject:image];
}
self.table1 = [[UITableView
alloc] initWithFrame:CGRectMake(0,
64,
100, 416)
style:(UITableViewStylePlain)];
self.table1.delegate =
self;
self.table1.dataSource =
self;
[self.view
addSubview:self.table1];
[_table1
release];
self.table2 = [[UITableView
alloc] initWithFrame:CGRectMake(110,
64,
100, 416)
style:(UITableViewStylePlain)];
self.table2.delegate =
self;
self.table2.dataSource =
self;
[self.view
addSubview:self.table2];
[_table2
release];
self.table3 = [[UITableView
alloc] initWithFrame:CGRectMake(220,
64,
100, 416)
style:(UITableViewStylePlain)];
self.table3.delegate =
self;
self.table3.dataSource =
self;
[self.view
addSubview:self.table3];
[_table3
release];
}
return
self;
}
- (void)viewDidLoad
{
[super
viewDidLoad];
// Do any additional setup after loading the view.
[self
setAutomaticallyAdjustsScrollViewInsets:NO];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView ==
self.table1) {
self.table2.contentOffset = scrollView.contentOffset;
self.table3.contentOffset = scrollView.contentOffset;
}
else if (scrollView ==
self.table2){
self.table1.contentOffset = scrollView.contentOffset;
self.table3.contentOffset = scrollView.contentOffset;
}
else{
self.table1.contentOffset = scrollView.contentOffset;
self.table2.contentOffset = scrollView.contentOffset;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.table2) {
return self.array1.count;
}else {
return self.array.count;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath
*)indexPath
{
UIImage *image = [self.array
objectAtIndex:indexPath.row];
return image.size.height *
100/ image.size.width;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
if (tableView == self.table2) {
NSString *str = @"kzss1";
MyCell *cell = [tableView
dequeueReusableCellWithIdentifier:str];
if (nil == cell) {
cell = [[[MyCell
alloc] initWithStyle:(UITableViewCellStyleSubtitle)
reuseIdentifier:str] autorelease];
}
UIImage *image = [self.array1
objectAtIndex:indexPath.row];
cell.myImageView.image = image;
return cell;
}
else {
NSString *str = @"kzss";
MyCell *cell = [tableView
dequeueReusableCellWithIdentifier:str];
if (nil == cell) {
cell = [[[MyCell
alloc] initWithStyle:(UITableViewCellStyleSubtitle)
reuseIdentifier:str] autorelease];
}
UIImage *image = [self.array
objectAtIndex:indexPath.row];
cell.myImageView.image = image;
return cell;
}
}
- (void)didReceiveMemoryWarning
{
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
@interface MyCell :
UITableViewCell
@property (nonatomic ,retain)
UIImageView *myImageView;
@end
@implementation MyCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString
*)reuseIdentifier
{
self = [super
initWithStyle:style
reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.myImageView = [[UIImageView
alloc] init];
[self.contentView
addSubview:self.myImageView];
[self.myImageView
release];
}
return
self;
}
- (void)layoutSubviews
{
[super
layoutSubviews];
// self.myImageView.frame = CGRectMake(0, 0,self.frame.size.width/3, self.frame.size.height);
self.myImageView.frame =
self.contentView.bounds;
}
- (void)awakeFromNib
{
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super
setSelected:selected
animated:animated];
// Configure the view for the selected state
}
@end
相关文章推荐
- javascript dom代码应用 简单的相册[firefox only]
- javascript dom代码应用 简单的相册[firefox only]
- AJAX实现一个简单的相册和里头包含一些DOM基础应用
- UITableViewCell的简单应用-书架
- javascript dom代码应用:简单的相册
- 使用C#开发一个简单的P2P应用
- HTA的简单应用
- Tomcat4/5连接池的设置及简单应用示例
- Tomcat4/5连接池的设置及简单应用示例
- J2ME应用实例——一个简单的计算器实现(附源代码)
- process类的简单应用
- 一个简单的定时器应用: VarTimer (java)
- Tomcat4/5连接池的设置及简单应用示例
- java(j2ee)应用-简单自定义标签开发全过程----之一(Inber)——JAVA夜未眠
- 有行统计项和列统计项的行列转换,以及EXCEL导入SQL的简单应用
- EJB中JNDI的逻辑名的使用及部署_{EJB之无状态会话Bean简单应用-学习与实践}续(inber原作)
- SQLSERVER扩展存储过程XP_CMDSHELL的简单应用
- 透明网关ProxyARP在APN上的简单应用
- [原创]用jar命令将Web应用打包成war文件的简单方法
- EJB之无状态会话Bean简单应用-学习与实践(Inber原作)