iOS 两个tableview的 瀑布流
1. [代码]Objective-C     
//
//  DocViewController.m
//  getrightbutton
//
//  Created by 隋文涛 on 12-12-9.
//  Copyright (c) 2012年 隋文涛. All rights reserved.
//

#import "DocViewController.h"
#define heightofimage(image) image.size.height*150.0/image.size.width

@interface DocViewController ()
{
    NSMutableArray *arrdata;
    NSMutableArray *arrdata1;
    NSMutableArray *arrdata2;
    NSMutableArray *arrdata1_1;
    NSMutableArray *arrdata2_1;
    float he1,he2;
}

@property (weak, nonatomic) IBOutlet UITableView *tableview01;
@property (weak, nonatomic) IBOutlet UITableView *tableview02;

@end

@implementation DocViewController
@synthesize tableview01,tableview02;

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Backhome) name:@"Back" object:nil];
    
    he1 = 0.0;
    he2 = 0.0;
    arrdata1 = [[NSMutableArray alloc] initWithCapacity:1];
    arrdata2 = [[NSMutableArray alloc] initWithCapacity:1];
    arrdata1_1 = [[NSMutableArray alloc] initWithCapacity:1];
    arrdata2_1 = [[NSMutableArray alloc] initWithCapacity:1];
    for (int i = 1; i < 11; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpeg",i]];
        float hecu = image.size.height*150.0/image.size.width;
        
        if (he2 >= he1) {
            he1 = he1 + hecu;
            NSArray *arr = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%d",i],[NSString stringWithFormat:@"%f",hecu], nil];
//            [arrdata1_1 addObject:[NSString stringWithFormat:@"%d",i]];
//            [arrdata1_1 addObject:[NSString stringWithFormat:@"%f",hecu]];
            [arrdata1 addObject:arr];
        }else{
            he2 = he2 + hecu;
            NSArray *arr = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%d",i],[NSString stringWithFormat:@"%f",hecu], nil];
            [arrdata2 addObject:arr];
        }
        NSLog(@"%f(h1 = %f,,,,h2 = %f)",hecu,he1,he2);
    }
    tableview01.showsVerticalScrollIndicator = NO;
    tableview02.showsVerticalScrollIndicator = NO;
    NSLog(@"%@+++++++%@",arrdata1,arrdata2);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    return 100;
    if (tableView == tableview01) {
        return [arrdata1 count];
    }else{
        return [arrdata2 count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    
    
    if (tableView == tableview01) {
//        tableview02
//        [tableview02 setContentOffset:tableview01.contentOffset];
        static NSString *id1 = @"sd1";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id1];
        if (cell == nil) {http://www.huiyi8.com/vi/
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CellView" owner:self options:nil];
            if (nib > 0) {
                cell = _ccell;
            }
        }
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpeg",[[[arrdata1 objectAtIndex:row] objectAtIndex:0] integerValue]]];
        UIImageView *imageview = (UIImageView *)[cell viewWithTag:101];
        [imageview setImage:image];vi模版大全
        CGRect rect = imageview.frame;
        rect.size.height = [[[arrdata1 objectAtIndex:row] objectAtIndex:1] floatValue];
        imageview.frame = rect;
        return cell;

}else{
//        [tableview01 setContentOffset:tableview02.contentOffset];
        static NSString *id = @"sd";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id];
        if (cell == nil) {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CellView" owner:self options:nil];
            if (nib > 0) {
                cell = _ccell;
            }
        }
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpeg",[[[arrdata2 objectAtIndex:row] objectAtIndex:0] integerValue]]];
        UIImageView *imageview = (UIImageView *)[cell viewWithTag:101];
        [imageview setImage:image];
        CGRect rect = imageview.frame;
        rect.size.height = [[[arrdata2 objectAtIndex:row] objectAtIndex:1] floatValue];
        imageview.frame = rect;
        return cell;

}
    return nil;
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    if (tableView == tableview01) {
        return [[[arrdata1 objectAtIndex:row] objectAtIndex:1] floatValue] +10;
    }else{
        return [[[arrdata2 objectAtIndex:row] objectAtIndex:1] floatValue] +10;
    }
    return 0.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DocwebViewController *controller = [[DocwebViewController alloc] init];
    [self presentModalViewController:controller animated:YES];
}

- (void)Backhome{
    [self dismissModalViewControllerAnimated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView == tableview01) {
        [tableview02 setContentOffset:tableview01.contentOffset];
    }else{
        [tableview01 setContentOffset:tableview02.contentOffset];
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
效果图:

最新文章

  1. leetcode 235. Lowest Common Ancestor of a Binary Search Tree
  2. 【转】CSS z-index 属性的使用方法和层级树的概念
  3. 4Web镇之旅:开始链接
  4. C#基础(四)
  5. .net转php laraval框架学习系列(四) 项目实战---View
  6. Shell函数返回值、删除函数、在终端调用函数
  7. 如何将txt的多行记录直接导入到mysql数据库
  8. 删除一个目录及其子目录下的所有.svn文件
  9. hdu 4288 离线线段树+间隔求和
  10. centos7的内核区别
  11. [Swift]LeetCode235. 二叉搜索树的最近公共祖先 | Lowest Common Ancestor of a Binary Search Tree
  12. jmeter保持登录
  13. 2、金融之关于BOLL
  14. 关于DBX Framewrok 和 FireDac 的一点随笔
  15. Socket网络编程--简单Web服务器(1)
  16. python day09作业答案
  17. DevOps需要的工具
  18. AsyncHelper
  19. Oracle 中TNS的作用
  20. unity, 删除animationClip中的position曲线

热门文章

  1. linux tomcat shutdown.sh 有时不能结束进程,使用如下指令进度重启
  2. SVG动画实践篇-无中生有的线条动画
  3. erlang debugger
  4. 安装Vmware增强工具
  5. weblogic运维时经常遇到的问题和常用的配置
  6. asyncTask 的execute和executeOnExecutor 方法
  7. SilverLight: 数据绑定(1)-绑定到数据对象
  8. jquery中text(),html(),val()在取值上的区别
  9. python(28)- 面向对象练习Ⅱ
  10. 分布式开源调度框架TBSchedule原理与应用