AppDelegate
#import "AppDelegate.h"
#import "MainViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
MainViewController * main = [[MainViewController alloc]init];
UINavigationController * naVC = [[UINavigationController alloc]initWithRootViewController:main];
[self.window setRootViewController:naVC];
[main release];
[naVC release];
return YES;
}
#import
@interface MainViewController : UIViewController
@property(nonatomic,retain)UITableView * rightable;
@property(nonatomic,retain)UITableView * midtable;
@property(nonatomic,retain)UITableView * leftable;
@property(nonatomic,retain)NSMutableArray * array;
@property(nonatomic,retain)NSMutableArray * array1;
@property(nonatomic,retain)NSMutableArray * array2;
#import "MainViewController.h"
#import "MyCell.h"
#import "Decell.h"
#import "AddCell.h"
@interface MainViewController ()
@end
@implementation MainViewController
-(void)dealloc
{
[_array release];
_array = nil;
[_array1 release];
_array1 = nil;
[_array2 release];
_array2 = nil;
[_leftable release];
_leftable = nil;
[_midtable release];
_midtable = nil;
[_rightable release];
_rightable = nil;
[super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.array = [[NSMutableArray alloc]init];
[_array release];
self.array1 = [[NSMutableArray alloc] init];
self.array2 = [[NSMutableArray alloc]init];
[_array2 release];
self.rightable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 105, 480) style:UITableViewStylePlain];
[_rightable release];
self.midtable = [[UITableView alloc]initWithFrame:CGRectMake(106, 0, 110, 480) style:UITableViewStylePlain];
[_midtable release];
self.leftable = [[UITableView alloc]initWithFrame:CGRectMake(215, 0, 105, 480) style:UITableViewStylePlain];
[_leftable release];
for (int i = 101; i < 105; i ++) {
NSString * str = [NSString stringWithFormat:@"%d.jpg",i];
[_array addObject:str];
}
for (int i = 105; i < 109; i ++) {
NSString * str = [NSString stringWithFormat:@"%d.jpg",i];
[_array1 addObject:str];
}
for (int i = 109; i < 113; i ++) {
NSString * str = [NSString stringWithFormat:@"%d.jpg",i];
[_array2 addObject:str];
}
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"瀑布流";
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
_rightable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_rightable.dataSource = self;
_rightable.delegate = self;
_rightable.tag = 100;
[self.view addSubview:_rightable];
_midtable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_midtable.dataSource = self;
_midtable.delegate = self;
_midtable.tag = 150;
[self.view addSubview:_midtable];
_leftable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_leftable.dataSource = self;
_leftable.delegate = self;
_leftable.tag = 200;
[self.view addSubview:_leftable];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView.tag == 100) {
return [_array count];
} else if (tableView.tag == 150){
return [_array1 count];
}
return [_array2 count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == 100) {
NSString * str = [_array objectAtIndex:indexPath.row];
UIImage * image = [UIImage imageNamed:str];
MyCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[[MyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
}
cell.myimageview.image = image;
return cell;
} else if (tableView.tag == 150){
NSString * str = [_array1 objectAtIndex:indexPath.row];
UIImage * image = [UIImage imageNamed:str];
AddCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[[AddCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
}
cell.myimageview.image = image;
return cell;
}
NSString * str = [_array2 objectAtIndex:indexPath.row];
UIImage * image = [UIImage imageNamed:str];
Decell * cell1 = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
if (cell1 == nil) {
cell1 = [[[Decell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell1"] autorelease];
}
cell1.myimageview.image = image;
return cell1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == 100) {
NSString * str = [_array objectAtIndex:indexPath.row];
UIImage * image = [UIImage imageNamed:str];
CGFloat cellH = image.size.height / image.size.width * 180;
return cellH;
} else if (tableView.tag == 150){
NSString * str = [_array1 objectAtIndex:indexPath.row];
UIImage * image = [UIImage imageNamed:str];
CGFloat cellH0 = image.size.height / image.size.width * 115;
return cellH0;
}
NSString * str1 = [_array2 objectAtIndex:indexPath.row];
UIImage * image1 = [UIImage imageNamed:str1];
CGFloat cellH1 = image1.size.height / image1.size.width * 140;
return cellH1;
}
//-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
// return 1;
//}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"scroll====%@",scrollView);
UITableView * view1 = (UITableView *)[self.view viewWithTag:100];
UITableView * view2 = (UITableView *)[self.view viewWithTag:150];
UITableView * view = (UITableView *)[self.view viewWithTag:200];
if (scrollView.tag == 100) {
view.contentOffset = scrollView.contentOffset;
}
if (scrollView.tag == 150) {
view1.contentOffset = scrollView.contentOffset;
}
if (scrollView.tag == 200) {
view2.contentOffset = scrollView.contentOffset;
}
}
#import
@interface MyCell : UITableViewCell
@property(nonatomic,retain)UIImageView * myimageview;
@end
#import "MyCell.h"
@implementation MyCell
-(void)dealloc
{
[_myimageview release];
[super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.myimageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150, 80)];
[self addSubview:self.myimageview];
[self.myimageview release];
}
return self;
}
//显示到屏幕前 会调用一次这个方法 用于利用数据给视图赋值
//cell将要出现的时候调用
- (void)layoutSubviews
{
[super layoutSubviews];
self.myimageview.frame = self.contentView.bounds;
}
#import
@interface Decell : UITableViewCell
@property(nonatomic,retain)UIImageView * myimageview;
#import "Decell.h"
@implementation Decell
-(void)dealloc
{
[_myimageview release];
[super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.myimageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 160)];
[self addSubview:self.myimageview];
[self.myimageview release];
}
return self;
}
//显示到屏幕前 会调用一次这个方法 用于利用数据给视图赋值
//cell将要出现的时候调用
- (void)layoutSubviews
{
[super layoutSubviews];
self.myimageview.frame = self.contentView.bounds;
}
#import
@interface AddCell : UITableViewCell
@property(nonatomic,retain)UIImageView * myimageview;
@end
#import "AddCell.h"
@implementation AddCell
-(void)dealloc
{
[_myimageview release];
[super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.myimageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 110, 165)];
[self addSubview:self.myimageview];
[self.myimageview release];
}
return self;
}