@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