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,如需轉載請自行聯系原作者

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/279516.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279516.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279516.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

word多級列表創建目錄_如何在Microsoft Word中創建和使用多級列表

word多級列表創建目錄Microsoft Word lets you easily create and format multilevel lists in your documents. You can choose from a variety of formatting options, including bulleted, numbered, or alphabetized lists. Let’s take a look. Microsoft Word使您可以輕松…

如何將多個Android Wear手表與單個手機配對

When it comes to “regular” wristwatches, a lot of people have different watches for different activities. It makes sense—a sporty watch for the gym, a nicer watch for the office, and a casual watch for everything else. If you want to live this life with…

Android系統的智能指針(輕量級指針、強指針和弱指針)的實現原理分析(3)...

提供引用計數器的類RefBase我們就暫時介紹到這里&#xff0c;后面我們再結合智能指針類一起分析&#xff0c;現在先來看看強指針類和弱指針類的定義。強指針類的定義我們在前面介紹輕量級指針的時候已經見到了&#xff0c;就是sp類了&#xff0c;這里就不再把它的代碼列出來了。…

ref:下一個項目為什么要用 SLF4J

ref:http://blog.mayongfa.cn/267.html 阿里巴巴 Java 開發手冊 前幾天阿里巴巴在云棲社區首次公開阿里官方Java代碼規范標準&#xff0c;就是一個PDF手冊&#xff0c;有命名規范&#xff0c;讓你知道自己原來取的每一個類名、變量名都是爛名字&#xff0c;真替你家未來孩子擔心…

洛谷P5055 【模板】可持久化文藝平衡樹(FHQ Treap)

題面 傳送門 題解 日常敲板子.jpg //minamoto #include<bits/stdc.h> #define R register #define inline __inline__ __attribute__((always_inline)) #define fp(i,a,b) for(R int i(a),I(b)1;i<I;i) #define fd(i,a,b) for(R int i(a),I(b)-1;i>I;--i) #define …

計算機突然藍屏無法啟動_為什么計算機無法立即啟動?

計算機突然藍屏無法啟動With the newer, more powerful hardware and improved operating systems that we have available to use these days, why does it still take as long as it does to fully boot a computer up each time? 借助我們如今可以使用的更新&#xff0c;更…

CCNA課堂練習:OSPF的介紹及配置

CCNA淺談OSPF的配置 今天我們來談談路由器OSPF的配置&#xff0c;那我先來介紹一下OSPF的特點&#xff1a;1、對網絡發生的變化能夠快速響應2、當網絡發生變化的時候發送觸發式更新?3、支持VLAN 4、管理方便ospf引用了區域的概念&#xff0c;區域分兩種&#xff1a;1、骨干區域…

vcenter 6.7 (vcsa)部署指南

閑言少敘&#xff0c;直達心靈。 一、部署提要1.1 vCenter Server Appliance(VCSA )6.7下載地址https://pan.baidu.com/s/1WUShsC23E2qIIBg7MPR87w 6lzb 二、安裝部署VCSA分為兩個階段安裝&#xff0c;下面我們開始第一階段2.1 打開之后&#xff0c;直接點擊安裝按鈕2.2部署設備…

如何停止Internet Explorer 11的建議站點?

Internet Explorer automatically suggests addresses and search results based on the partial address you’re typing out. If this feature irritates you, read on as we learn how to turn it off. Internet Explorer會根據您鍵入的部分地址自動建議地址和搜索結果。 如…

什么是SG?+SG模板

先&#xff0c;定義一下 狀態Position P 先手必敗 N x先手必勝 操作方法&#xff1a; 反向轉移 相同狀態 不同位置 的一對 相當于無 對于ICG游戲&#xff0c;我們可以將游戲中每一個可能發生的局面表示為一個點。并且若存在局面i和局面j&#xff0c;且j是i的后繼局面(即局面i可…

【桌面虛擬化】之三 Persistent vs NonP

作者&#xff1a;范軍 &#xff08;Frank Fan&#xff09; 新浪微博&#xff1a;frankfan7 在【桌面虛擬化】之二類型及案例中我們探討了桌面虛擬化的兩種架構&#xff0c;HostedVirtual Desktop (VDI) 和 Published Desktop/App. 本文深入分析其中VDI的兩種桌面類型&#xff0…

H5 video 開發問題及相關知識點

相關鏈接&#xff1a;H5 video 的使用H5 video 全屏播放? video點播與直播H5 video目前所有瀏覽器都支持的視頻格式是MP4格式&#xff0c;所以mp4應當是點播web視頻的首選格式。而在直播視頻上&#xff0c;H5 video只在移動端原生支持HLS流的直播視頻(Mac safari video標簽也支…

Mybatis-Generator自動生成XML文件以及接口和實體類

整合了MySQL和Oracle配置文件生成方法 這個是整個文件夾的下載地址&#xff1a;http://www.codepeople.cn/download 主要給大家介紹一下generatorConfig.xml文件的配置&#xff0c;以及生成后的文件。 generatorConfig.xml <?xml version"1.0" encoding"UTF…

如何在Windows 10上設置默認Linux發行版

Windows 10 now allows you to install multiple Linux environments, starting with the Fall Creators Update. If you have multiple Linux environments, you can set your default and switch between them. Windows 10現在允許您從Fall Creators Update開始安裝多個Linux…

mysql全備份+增量備份筆記總結

備份基礎知識 冷備&#xff08;cold backup&#xff09;&#xff1a;需要關mysql服務&#xff0c;讀寫請求均不允許狀態下進行&#xff1b; 溫備&#xff08;warm backup&#xff09;&#xff1a; 服務在線&#xff0c;但僅支持讀請求&#xff0c;不允許寫請求&#xff1b; 熱備…

pjax學習

PJAX 介紹 紅薯 發布于 2012/04/11 22:06閱讀 61K收藏 116評論 11jQuery.Pjax kissy開發四年只會寫業務代碼&#xff0c;分布式高并發都不會還做程序員&#xff1f;->>> 介紹 pushState是一個可以操作history的api&#xff0c;該api的介紹和使用請見這里&#xff1a…

SQL Server 2000詳細安裝過程及配置

說明&#xff1a;這篇文章是幾年前我發布在網易博客當中的原創文章&#xff0c;但由于網易博客現在要停止運營了&#xff0c;所以我就把這篇文章搬了過來&#xff0c;雖然現如今SQL Server 2000軟件早已經過時了&#xff0c;但仍然有一部分人在使用它&#xff0c;尤其是某些高校…

移動應用ios和網頁應用_如何在iOS上一次移動多個應用

移動應用ios和網頁應用Apple doesn’t really believe in detailed instruction manuals, so some handy tricks slip through the cracks. One such trick we’ve recently discovered is that you can move multiple app icons at once on iOS. Here’s how. Apple并不真正相…

如何將內核靜態庫編譯連接到驅動程序中去【轉】

轉自&#xff1a;http://blog.csdn.net/ganjianfeng2003/article/details/8089551 如何將內核靜態庫編譯連接到驅動程序中去 2010-12-07 08:27 331人閱讀 評論(1) 收藏 舉報 http://blog.chinaunix.net/u2/61663/showart_2404744.html 剛上郵箱的時候發現一位網友向我詢問這個問…

2018-2019 20165226 Exp9 Web安全基礎

2018-2019 20165226 Exp9 Web安全基礎 目錄 一、實驗內容說明及基礎問題回答 二、實驗過程 Webgoat準備XSS攻擊 ① Phishing with XSS 跨站腳本釣魚攻擊② Stored XSS Attacks 存儲型XSS攻擊③ Reflected XSS Attacks 反射型XSS攻擊 CSRF攻擊 ① Cross Site Request Forgery(CS…