瀑布流相册
TestAppDelegate.m文件下的内容
#import "TestAppDelegate.h"
#import "MainViewController.h"
@implementation TestAppDelegate
- (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];
[self.window makeKeyAndVisible];
MainViewController *mainVC = [[MainViewController alloc]init];
UINavigationController *naviVC = [[UINavigationController alloc]initWithRootViewController:mainVC];
self.window.rootViewController = naviVC;
[ _window release];
[mainVC release];
[naviVC release];
return YES;
}
-(void)dealloc
{
[_window release];
[super dealloc];
}
MainViewController.h下的内容
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *array;
@property (nonatomic,retain)UITableView *tableViewS;
@property (nonatomic, retain)UITableView *tableViewT;
@property (nonatomic, retain)NSMutableArray *arrayS;
@property (nonatomic, retain)NSMutableArray *arrayT;
MainViewConroller.m下的内容
#import "MainViewController.h"
#import "MycellCell.h"
#import "MySecondCell.h"
#import "MyThirdCell.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.arrayT = [NSMutableArray array];
for (int i = 39; i < 59; i++) {
UIImage *imageB = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
[self.arrayT addObject:imageB];
}
self.arrayS = [NSMutableArray array];
for (int i = 20; i < 38; i++) {
UIImage *imageA = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
[self.arrayS addObject:imageA];
}
self.array = [NSMutableArray array];
for (int i = 1; i < 19 ; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg", i]];
[self.array addObject:image];
}
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, 106, 416) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
[self.tableView release];
self.tableViewS = [[UITableView alloc]initWithFrame:CGRectMake(106, 64, 106, 416) style:UITableViewStylePlain];
self.tableViewS.delegate = self;
self.tableViewS.dataSource = self;
[self.view addSubview:self.tableViewS];
[self.tableViewS release];
self.tableViewT = [[UITableView alloc]initWithFrame:CGRectMake(212, 64, 108, 416) style:UITableViewStylePlain];
self.tableViewT.delegate = self;
self.tableViewT.dataSource = self;
[self.view addSubview:self.tableViewT];
[self.tableViewT release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.tableView) {
NSString *string = @"reuse";
MycellCell *cell = [tableView dequeueReusableCellWithIdentifier:string];
if (nil == cell) {
cell = [[[MycellCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:string]autorelease];
}
UIImage *image = [self.array objectAtIndex:indexPath.row];
cell.MyImageView.image = image;
return cell;
}else if (tableView == self.tableViewS) {
NSString *stringA = @"reuseA";
MySecondCell *cellA = [tableView dequeueReusableCellWithIdentifier:stringA];
if (nil ==cellA) {
cellA = [[MySecondCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:stringA];
}
UIImage *imageA = [self.arrayS objectAtIndex:indexPath.row];
cellA.Myimage.image = imageA;
return cellA;
}else {
NSString *stringB = @"reuseB";
MyThirdCell *cellB = [tableView dequeueReusableCellWithIdentifier:stringB];
if (nil == cellB) {
cellB = [[MyThirdCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:stringB];
}
UIImage *imageC = [self.arrayT objectAtIndex:indexPath.row];
cellB.MyImageViewT.image = imageC;
return cellB;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *image = [self.array objectAtIndex:indexPath.row];
CGFloat cellHight = tableView.bounds.size.width * image.size.height / image.size.width;
UIImage *imageA = [self.arrayS objectAtIndex:indexPath.row];
CGFloat cellAight = tableView.bounds.size.width * imageA.size.height / imageA.size.width;
UIImage *imageB = [self.arrayT objectAtIndex:indexPath.row];
CGFloat cellBight = tableView.bounds.size.width * imageB.size.height / imageB.size.width;
return cellBight;
return cellAight;
return cellHight;
}
//让三个tableView的indexpath值等于scrollerView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
self.tableView.contentOffset = scrollView.contentOffset;
self.tableViewS.contentOffset = scrollView.contentOffset;
self.tableViewT.contentOffset = scrollView.contentOffset;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
MyCellCell.h下的文件
#import <UIKit/UIKit.h>
@interface MycellCell : UITableViewCell
@property (nonatomic, retain)UIImageView *MyImageView;
@end
MyCellCell.m下的文件
#import "MycellCell.h"
@implementation MycellCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
_MyImageView = [[UIImageView alloc]init];
[self.contentView addSubview:_MyImageView];
[_MyImageView release];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
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
MSecondCell.h下的文件
#import <UIKit/UIKit.h>
@interface MySecondCell : UITableViewCell
@property (nonatomic, retain)UIImageView *Myimage;
@end
MSecondCell.m下的文件
#import "MySecondCell.h"
@implementation MySecondCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
_Myimage = [[UIImageView alloc]init];
[self.contentView addSubview:_Myimage];
[_Myimage release];
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
self.Myimage.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
MyThirdCell.h下的文件
#import <UIKit/UIKit.h>
@interface MyThirdCell : UITableViewCell
@property (nonatomic, retain)UIImageView *MyImageViewT;
@end
MyThirdCell.m下的文件
#import "MyThirdCell.h"
@implementation MyThirdCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
_MyImageViewT = [[UIImageView alloc]init];
[self.contentView addSubview:_MyImageViewT];
[_MyImageViewT release];
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
self.MyImageViewT.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
IOSUI瀑布流相册的实现
最新推荐文章于 2021-12-04 13:58:52 发布