iOS 两个tableview 实现 瀑布流

来源:互联网 发布:网络监控软件排行 编辑:程序博客网 时间:2024/05/21 12:08
001//
002// DocViewController.m
003// getrightbutton
004//
005// Created by 隋文涛 on 12-12-9.
006// Copyright (c) 2012年 隋文涛. All rights reserved.
007//
008 
009#import"DocViewController.h"
010#defineheightofimage(image)image.size.height*150.0/image.size.width
011 
012@interfaceDocViewController ()
013{
014    NSMutableArray*arrdata;
015    NSMutableArray*arrdata1;
016    NSMutableArray*arrdata2;
017    NSMutableArray*arrdata1_1;
018    NSMutableArray*arrdata2_1;
019    floathe1,he2;
020}
021 
022@property (weak, nonatomic)IBOutlet UITableView *tableview01;
023@property (weak, nonatomic)IBOutlet UITableView *tableview02;
024 
025@end
026 
027@implementationDocViewController
028@synthesizetableview01,tableview02;
029 
030- (void)viewDidLoad
031{
032    [superviewDidLoad];
033    //Do any additional setup after loading the view, typically from anib.
034    [[NSNotificationCenterdefaultCenter] addObserver:self selector:@selector(Backhome)name:@"Back"object:nil];
035     
036    he1= 0.0;
037    he2= 0.0;
038    arrdata1= [[NSMutableArray alloc] initWithCapacity:1];
039    arrdata2= [[NSMutableArray alloc] initWithCapacity:1];
040    arrdata1_1= [[NSMutableArray alloc] initWithCapacity:1];
041    arrdata2_1= [[NSMutableArray alloc] initWithCapacity:1];
042    for(inti = 1; i < 11; i++) {
043        UIImage*image = [UIImage imageNamed:[NSStringstringWithFormat:@"%d.jpeg",i]];
044        floathecu =image.size.height*150.0/image.size.width;
045         
046        if(he2 >= he1) {
047            he1= he1 + hecu;
048            NSArray*arr = [[NSArray alloc] initWithObjects:[NSStringstringWithFormat:@"%d",i],[NSStringstringWithFormat:@"%f",hecu], nil];
049//           [arrdata1_1 addObject:[NSStringstringWithFormat:@"%d",i]];
050//           [arrdata1_1 addObject:[NSStringstringWithFormat:@"%f",hecu]];
051            [arrdata1addObject:arr];
052        }else{
053            he2= he2 + hecu;
054            NSArray*arr = [[NSArray alloc] initWithObjects:[NSStringstringWithFormat:@"%d",i],[NSStringstringWithFormat:@"%f",hecu], nil];
055            [arrdata2addObject:arr];
056        }
057        NSLog(@"%f(h1= %f,,,,h2 = %f)",hecu,he1,he2);
058    }
059    tableview01.showsVerticalScrollIndicator= NO;
060    tableview02.showsVerticalScrollIndicator= NO;
061    NSLog(@"%@+++++++%@",arrdata1,arrdata2);
062}
063 
064-(NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
065//   return 100;
066    if(tableView == tableview01) {
067        return[arrdata1 count];
068    }else{
069        return[arrdata2 count];
070    }
071    return0;
072}
073 
074- (UITableViewCell*)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{
075    NSIntegerrow = indexPath.row;
076     
077     
078    if(tableView == tableview01) {
079//       tableview02
080//       [tableview02setContentOffset:tableview01.contentOffset];
081        staticNSString *id1 = @"sd1";
082        UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:id1];
083        if(cell == nil) {
084            NSArray*nib = [[NSBundle mainBundle] loadNibNamed:@"CellView"owner:selfoptions:nil];
085            if(nib > 0) {
086                cell= _ccell;
087            }
088        }
089        UIImage*image = [UIImage imageNamed:[NSStringstringWithFormat:@"%d.jpeg",[[[arrdata1objectAtIndex:row] objectAtIndex:0] integerValue]]];
090        UIImageView*imageview = (UIImageView *)[cell viewWithTag:101];
091        [imageviewsetImage:image];
092        CGRectrect = imageview.frame;
093        rect.size.height= [[[arrdata1 objectAtIndex:row] objectAtIndex:1]floatValue];
094        imageview.frame= rect;
095        returncell;
096 
097    }else{
098//       [tableview01setContentOffset:tableview02.contentOffset];
099        staticNSString *id = @"sd";
100        UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:id];
101        if(cell == nil) {
102            NSArray*nib = [[NSBundle mainBundle] loadNibNamed:@"CellView"owner:selfoptions:nil];
103            if(nib > 0) {
104                cell= _ccell;
105            }
106        }
107        UIImage*image = [UIImage imageNamed:[NSStringstringWithFormat:@"%d.jpeg",[[[arrdata2objectAtIndex:row] objectAtIndex:0] integerValue]]];
108        UIImageView*imageview = (UIImageView *)[cell viewWithTag:101];
109        [imageviewsetImage:image];
110        CGRectrect = imageview.frame;
111        rect.size.height= [[[arrdata2 objectAtIndex:row] objectAtIndex:1]floatValue];
112        imageview.frame= rect;
113        returncell;
114 
115    }
116    returnnil;
117}
118 
119- (float)tableView:(UITableView *)tableViewheightForRowAtIndexPath:(NSIndexPath *)indexPath{
120    NSIntegerrow = indexPath.row;
121    if(tableView == tableview01) {
122        return[[[arrdata1 objectAtIndex:row] objectAtIndex:1]floatValue] +10;
123    }else{
124        return[[[arrdata2 objectAtIndex:row] objectAtIndex:1]floatValue] +10;
125    }
126    return0.0;
127}
128 
129- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
130    DocwebViewController*controller = [[DocwebViewController alloc] init];
131    [selfpresentModalViewController:controller animated:YES];
132}
133 
134- (void)Backhome{
135    [selfdismissModalViewControllerAnimated:YES];
136}
137 
138- (void)scrollViewDidScroll:(UIScrollView*)scrollView{
139    if(scrollView == tableview01) {
140        [tableview02setContentOffset:tableview01.contentOffset];
141    }else{
142        [tableview01setContentOffset:tableview02.contentOffset];
143    }
144     
145}
146 
147- (void)didReceiveMemoryWarning
148{
149    [superdidReceiveMemoryWarning];
150    //Dispose of any resources that can be recreated.
151}
152 
153@end
iOS <wbr>两个tableview <wbr>实现 <wbr>瀑布流
0 0
原创粉丝点击