UITableViewCell的简单应用-瀑布形相册

@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






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值