日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

8月19学习练习[两三个TableView并排显示]

發布時間:2023/12/9 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 8月19学习练习[两三个TableView并排显示] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

要求:在一個view中顯示兩個tableView,要求左右顯示的內容以及行數不一樣,且左邊每行顯示兩張圖片(分別3個一輪回,2個一輪回)并且顯示中國的城市名,右邊顯示水果名。點擊時分別顯示城市名或水果名的對話框(偶數的城市不能點擊)(所選的圖片長短比例不一致)

運行圖:


步驟:

1.創建一個tableCell.xib


2.viewController.h:

#import <UIKit/UIKit.h> @interface DXWViewController : UIViewController<UITableViewDataSource,UITableViewDelegate> @property (retain, nonatomic) IBOutlet UITableViewCell *ccell; @end
3.viewController.m:

// // DXWViewController.m // 兩個tableView // // Created by 丁小未 on 13-8-19. // Copyright (c) 2013年 dingxiaowei. All rights reserved. // #import "DXWViewController.h" #define heightofimage(image) image.size.height*150.0/image.size.width @interface DXWViewController () { NSMutableArray *arrdata; NSMutableArray *arrdata1; NSMutableArray *arrdata2; NSMutableArray *arrdata2_1; NSMutableArray *arrdata3; float he1,he2; } @property (retain, nonatomic) IBOutlet UITableView *tableview1; @property (retain, nonatomic) IBOutlet UITableView *tableview2; @property (retain, nonatomic) IBOutlet UITableView *tableview3; @end @implementation DXWViewController @synthesize tableview1,tableview2,tableview3; - (void)viewDidLoad { [super viewDidLoad]; [[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]; arrdata3 = [[NSMutableArray alloc] initWithObjects:@"蘋果",@"香蕉",@"梨子",@"菠蘿",@"桃子",@"西瓜",@"葡萄",@"凌檬",@"櫻桃", @"芒果",nil]; arrdata2_1 = [[NSMutableArray alloc] initWithObjects:@"江蘇", @"南京",@"河北",@"武漢",@"南通",@"北京",@"合肥",@"天津",@"長沙",@"蘇州",nil]; for (int i=1; i<11; i++) { UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpeg",i]]; float hecu = image.size.height *150/image.size.width; if (he2>=he1) { he1 = he1 +hecu; NSArray *arr = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%d",i],[NSString stringWithFormat:@"%f",hecu], nil]; [arrdata1 addObject:arr]; } else { he2 = he2 + hecu; NSArray *arr = [[NSArray alloc] initWithObjects:[NSString stringWithFormat:@"%d",i],[NSString stringWithFormat:@"%f",hecu], nil]; [arrdata2 addObject:arr]; } } tableview1.showsVerticalScrollIndicator = NO; tableview2.showsVerticalScrollIndicator = NO; NSLog(@"%@+++++++%@",arrdata1,arrdata2); } //兩個tableview顯示的行數 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (tableView == tableview1) { return [arrdata1 count]; }else if(tableView == tableview2){ return [arrdata2 count]; } else { return [arrdata3 count]*4; } return 0; } //兩個tableview顯示的高度 - (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ NSInteger row = indexPath.row; if (tableView == tableview1) { return [[[arrdata1 objectAtIndex:row] objectAtIndex:1] floatValue] +10; }else if(tableView == tableview2){ return [[[arrdata2 objectAtIndex:row] objectAtIndex:1] floatValue] +10; } else { return 44; } } //兩個tableview一起滾動 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ if (scrollView == tableview1) { [tableview2 setContentOffset:tableview1.contentOffset]; } else if(scrollView = tableview2){ [tableview1 setContentOffset:tableview2.contentOffset]; } } //tableviewcell的初始化 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = indexPath.row; if (tableView == tableview1) { static NSString *id1 = @"sd1"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:id1]; 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",[[[arrdata1 objectAtIndex:row] objectAtIndex:0] integerValue]]]; UIImageView *imageview = (UIImageView *)[cell viewWithTag:101]; [imageview setImage:image]; CGRect rect = imageview.frame; rect.size.height = [[[arrdata1 objectAtIndex:row] objectAtIndex:1] floatValue]; imageview.frame = rect; return cell; } else if(tableView == tableview2) { 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; } //創建UILabel UILabel *label = [[UILabel alloc] init]; label.text = [arrdata2_1 objectAtIndex:indexPath.row]; label.frame = CGRectMake(10, 7, 100, 35); //將UILabel添加到contentView中 [cell.contentView addSubview:label]; } 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; } else if(tableView == tableview3) { NSString *identifier = @"aaa";//創建一個表示符 //詢問帶這種標志的可以用的cell有沒有 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier]; } int row = [indexPath row];//需要顯示的是第幾行 cell.textLabel.text = [arrdata3 objectAtIndex:row%[arrdata3 count]]; return cell; } return nil; } //點擊某行的時候執行的操作 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (tableView == tableview3) { NSString * str= [arrdata3 objectAtIndex:[indexPath row]%[arrdata3 count]]; UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"你選中的水果" message:str delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; [a show]; [a release]; //取消選中 [tableView deselectRowAtIndexPath:indexPath animated:YES]; } } //將要選中某行時候做的事情,常用來判斷某行是否能點擊 -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { //偶數行不能點擊 if ([indexPath row]%2==1) { return nil; } return indexPath; } - (void)Backhome{ [self dismissModalViewControllerAnimated:YES]; } - (void)dealloc { [self.ccell release]; [self.tableview1 release]; [self.tableview2 release]; [self.tableview3 release]; [super dealloc]; } @end


















本文轉蓬萊仙羽51CTO博客,原文鏈接:http://blog.51cto.com/dingxiaowei/1366560,如需轉載請自行聯系原作者

總結

以上是生活随笔為你收集整理的8月19学习练习[两三个TableView并排显示]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 能在线看的av | 捆绑凌虐一区二区三区 | 欧美熟妇交换久久久久久分类 | 国产又粗又猛视频免费 | 国产精品jizz在线观看美国 | 中文字幕国产亚洲 | 97激情| 国产免费视频 | 猫咪av在线 | 亚洲精品中文在线 | 日日久 | 欧美性插插 | 国产激情二区 | 欧美 日韩 高清 | 亚洲aaaa级特黄毛片 | 人人精品久久 | 成人av网址在线观看 | chinesepron hd videos国产91 | 亚洲五月花 | 超碰自拍| 亚洲看片| 另类老妇性bbwbbw图片 | 国模视频一区二区 | 办公室摸腿吻胸激情视频 | 成人在线一区二区三区 | 亚洲AV乱码国产精品观看麻豆 | 国产中文字幕在线 | 里番acg★同人里番本子大全 | av影片在线播放 | 日韩中文字幕av在线 | 91中文在线观看 | av影视网| 性xxxx另类xxⅹ | 日韩中文在线一区 | 91黄址 | 国产黑丝一区二区 | 国产在线精品播放 | 国产欧美精品久久 | 日本裸体网站 | 好男人影视www | 久久久久久九九 | 日韩大片在线 | 天天干夜夜骑 | 在线日韩中文字幕 | 青青青国内视频在线观看软件 | 嫩色av | 性色av一区 | 啪啪av网| 欧美色图久久 | 成人一级免费视频 | 国产五月天婷婷 | 寂寞人妻瑜伽被教练日 | 九七在线视频 | 日韩大片av | 蜜臀久久99精品久久久无需会员 | 精品肉丝脚一区二区三区 | 国产一区 在线播放 | 99热r| 日韩中文字幕av电影 | 欧美xxxx18| 中文在线字幕免费观看电 | 一级二级三级视频 | 婷婷天堂网 | www.国产精品视频 | 精品少妇久久久 | 黄色一级大片在线免费看国产一 | 亚洲永久精品国产 | 天天综合入口 | www.四虎com| 在线观看黄色国产 | xvideos永久免费入口 | 亚洲一区二区精品在线 | 大度亲吻原声视频在线观看 | 台湾佬综合网 | 一区二区三区视频 | 男生草女生的视频 | 外国一级片 | 青草视频免费看 | 精品视频在线观看 | 在线观看亚洲av每日更新 | 久久精品夜色噜噜亚洲a∨ 中文字幕av网 | 麻豆偷拍 | 日本泡妞视频 | 操操操操操操操操操操 | 操极品美女 | 顶级黄色片 | 国产原创麻豆 | 国产欧美三级 | 69久久精品| 欧洲高潮三级做爰 | 中文字幕人妻一区二区三区视频 | 午夜亚洲精品 | 国产一区二区三区91 | 欧美黄色一区二区 | 人妻熟女aⅴ一区二区三区汇编 | 亚洲天天 | 91精品专区| 向日葵视频在线 | 国产精品扒开做爽爽爽的视频 |