一,效果图。

二,工程图。

三,代码。

RootViewController.h

  1. #import <UIKit/UIKit.h>
  2. #import "customCell.h"
  3.  
  4. @interface RootViewController : UIViewController
  5. <UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,UISearchDisplayDelegate>
  6. {
  7. customCell * cell;
  8. NSMutableArray * dataArray;
  9. NSMutableArray * imageArray;
  10. UIScrollView * scrollerView;
  11. UITableView * tableOneView;
  12. UITableView * tableTowView;
  13. UITableView * tableThreeView;
  14. UITableView * tableFourView;
  15. UISearchDisplayController * scrollerControl;
  16. }
  17.  
  18. @end

RootViewController.m

  1. #import "RootViewController.h"
  2. #import "customCell.h"
  3.  
  4. @interface RootViewController ()
  5.  
  6. @end
  7.  
  8. @implementation RootViewController
  9.  
  10. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  11. {
  12. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  13. if (self) {
  14. // Custom initialization
  15. }
  16. return self;
  17. }
  18.  
  19. - (void)viewDidLoad
  20. {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23.  
  24. //初始化背景图
  25. [self initBackgroundView];
  26. }
  27. -(void)initBackgroundView
  28. {
  29. self.navigationController.navigationBarHidden=YES;
  30.  
  31. dataArray = [[NSMutableArray alloc]initWithObjects:@"热门微博",@"热门话题",@"随便看看",@"二维码",
  32. @"周边的微博",@"周边的人",@"微吧",@"微博会员",
  33. @"新浪早晚报",@"微公益",@"微博应用",@"游戏",
  34. @"微刊",@"手机微博",@"微群",@"微相册",
  35. @"名人堂",@"人气草根",@"微博精选",@"猜你喜欢",
  36. @"手机新浪网",@"掌中新浪",@"天气通",@"微漫画",
  37. @"聊天",@"看点",@"微盘",@"微收藏",
  38. @"图钉",@"限免换享",@"淘身边",@"微美食",
  39. @"新浪拍客",@"博客",@"充话费",@"MOMO岛",
  40. @"网址导航",@"新浪视野",@"微数据",@"新浪彩票",nil];
  41. imageArray = [[NSMutableArray alloc] initWithObjects:@"0.png",@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png",@"7.png",@"8.png",@"9.png",@"10.png",@"11.png",@"12.png",@"13.png",@"14.png",@"15.png",@"16.png",@"17.png",@"18.png",@"19.png",@"20.png",@"21.png",@"22.png",@"23.png",@"24.png",@"25.png",@"26.png",@"27.png",@"28.png",@"29.png",@"30.png",@"31.png",@"32.png",@"33.png",@"34.png",@"35.png",@"36.png",@"37.png",@"38.png",@"39.png", nil];
  42.  
  43. //scrollerView
  44. scrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460-44-44)];
  45. scrollerView.contentSize = CGSizeMake(320*4, 460-44-44);
  46. scrollerView.bounces = YES;
  47. scrollerView.tag = 101;
  48. scrollerView.showsHorizontalScrollIndicator = NO;
  49. scrollerView.pagingEnabled = YES;
  50. scrollerView.delegate = self;
  51. [self.view addSubview:scrollerView];
  52.  
  53. //tableOne
  54. tableOneView = [[UITableView alloc] initWithFrame:CGRectMake(0, 44, 320, 460-44-44-44) style:UITableViewStylePlain];
  55. tableOneView.delegate = self;
  56. tableOneView.dataSource = self;
  57. tableOneView.bounces=NO;
  58. [tableOneView setSeparatorColor:[UIColor clearColor]];
  59.  
  60. //tableTwo
  61. tableTowView = [[UITableView alloc] initWithFrame:CGRectMake(320, 44, 320, 460-44-44-44) style:UITableViewStylePlain];
  62. tableTowView.delegate = self;
  63. tableTowView.dataSource = self;
  64. tableTowView.bounces=NO;
  65. [tableTowView setSeparatorColor:[UIColor clearColor]];
  66.  
  67. //tableThree
  68. tableThreeView = [[UITableView alloc]initWithFrame:CGRectMake(320*2, 44, 320, 460-44-44-44) style:UITableViewStylePlain];
  69. tableThreeView.delegate = self;
  70. tableThreeView.dataSource = self;
  71. tableThreeView.bounces=NO;
  72. [tableThreeView setSeparatorColor:[UIColor clearColor]];
  73.  
  74. //tableFour
  75. tableFourView = [[UITableView alloc] initWithFrame:CGRectMake(320*3, 44, 320, 460-44-44-44) style:UITableViewStylePlain];
  76. tableFourView.delegate = self;
  77. tableFourView.dataSource = self;
  78. tableFourView.bounces=NO;
  79. [tableFourView setSeparatorColor:[UIColor clearColor]];
  80.  
  81. [scrollerView addSubview:tableFourView];
  82. [scrollerView addSubview:tableThreeView];
  83. [scrollerView addSubview:tableTowView];
  84. [scrollerView addSubview:tableOneView];
  85.  
  86. //searchbar
  87. UISearchBar * searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
  88. searchBar.placeholder = @"搜索";
  89. searchBar.delegate = self;
  90. searchBar.showsCancelButton = YES;
  91. [self.view addSubview:searchBar];
  92.  
  93. //searchcontroller
  94. scrollerControl = [[UISearchDisplayController alloc]initWithSearchBar:searchBar contentsController:self];
  95. scrollerControl.delegate = self;
  96. scrollerControl.searchResultsDataSource = self;
  97. scrollerControl.searchResultsDelegate = self;
  98.  
  99. }
  100. #pragma -mark -UITableViewDelegate
  101. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  102. {
  103. return 3;
  104. }
  105. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107. return 100;
  108. }
  109. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. static int i = 0;
  112. static int j = 0;
  113. NSString * strID = @"ID";
  114. cell = [tableView dequeueReusableCellWithIdentifier:strID];
  115. if (cell == nil) {
  116. cell = [[customCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:strID];
  117. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  118.  
  119. cell.button1.tag = i++;
  120. cell.button2.tag = i++;
  121. cell.button3.tag = i++;
  122. cell.button4.tag = i++;
  123. cell.label1.tag = j++;
  124. cell.label2.tag = j++;
  125. cell.label3.tag = j++;
  126. cell.label4.tag = j++;
  127.  
  128. if (cell.label1.tag >= 40 || cell.button1.tag >= 40) {
  129. return cell;
  130. }
  131. }
  132.  
  133. [cell.label1 setText:[NSString stringWithFormat:@"%@",[dataArray objectAtIndex:cell.label1.tag]]];
  134. [cell.label2 setText:[NSString stringWithFormat:@"%@",[dataArray objectAtIndex:cell.label2.tag]]];
  135. [cell.label3 setText:[NSString stringWithFormat:@"%@",[dataArray objectAtIndex:cell.label3.tag]]];
  136. [cell.label4 setText:[NSString stringWithFormat:@"%@",[dataArray objectAtIndex:cell.label4.tag]]];
  137.  
  138. [cell.button1 setImage:[UIImage imageNamed:[imageArray objectAtIndex:cell.button1.tag]] forState:UIControlStateNormal];
  139. [cell.button2 setImage:[UIImage imageNamed:[imageArray objectAtIndex:cell.button2.tag]] forState:UIControlStateNormal];
  140. [cell.button3 setImage:[UIImage imageNamed:[imageArray objectAtIndex:cell.button3.tag]] forState:UIControlStateNormal];
  141. [cell.button4 setImage:[UIImage imageNamed:[imageArray objectAtIndex:cell.button4.tag]] forState:UIControlStateNormal];
  142.  
  143. [cell.button1 addTarget:self action:@selector(doClickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  144. [cell.button2 addTarget:self action:@selector(doClickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  145. [cell.button3 addTarget:self action:@selector(doClickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  146. [cell.button4 addTarget:self action:@selector(doClickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  147. return cell;
  148. }
  149. -(void)doClickButtonAction:(UIButton *)btn
  150. {
  151. NSLog(@"--btn.tag--%i",btn.tag);
  152. }
  153.  
  154. - (void)didReceiveMemoryWarning
  155. {
  156. [super didReceiveMemoryWarning];
  157. // Dispose of any resources that can be recreated.
  158. }

customCell.h

  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface customCell : UITableViewCell
  4. {
  5. UIButton * button1;
  6. UIButton * button2;
  7. UIButton * button3;
  8. UIButton * button4;
  9. UILabel * label1;
  10. UILabel * label2;
  11. UILabel * label3;
  12. UILabel * label4;
  13. }
  14. @property (nonatomic,retain)UIButton * button1;
  15. @property (nonatomic,retain)UIButton * button2;
  16. @property (nonatomic,retain)UIButton * button3;
  17. @property (nonatomic,retain)UIButton * button4;
  18. @property (nonatomic,retain)UILabel * label1;
  19. @property (nonatomic,retain)UILabel * label2;
  20. @property (nonatomic,retain)UILabel * label3;
  21. @property (nonatomic,retain)UILabel * label4;
  22. @end

customCell.m

  1. #import "customCell.h"
  2.  
  3. @implementation customCell
  4. @synthesize button1;
  5. @synthesize button2;
  6. @synthesize button3;
  7. @synthesize button4;
  8. @synthesize label1;
  9. @synthesize label2;
  10. @synthesize label3;
  11. @synthesize label4;
  12.  
  13. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  14. {
  15. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  16. if (self) {
  17. // Initialization code
  18.  
  19. button1 = [UIButton buttonWithType:UIButtonTypeCustom];
  20. button1.frame = CGRectMake(5, 10, 70, 60);
  21.  
  22. button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  23. button2.frame = CGRectMake(85, 10, 70, 60);
  24.  
  25. button3 = [UIButton buttonWithType:UIButtonTypeCustom];
  26. button3.frame = CGRectMake(165, 10, 70, 60);
  27.  
  28. button4 = [UIButton buttonWithType:UIButtonTypeCustom];
  29. button4.frame = CGRectMake(245, 10, 70, 60);
  30.  
  31. [self addSubview:button1];
  32. [self addSubview:button2];
  33. [self addSubview:button3];
  34. [self addSubview:button4];
  35.  
  36. label1 = [[UILabel alloc] initWithFrame:CGRectMake(5, 75, 70, 20)];
  37. label1.font = [UIFont systemFontOfSize:12];
  38. label1.textAlignment = NSTextAlignmentCenter;
  39.  
  40. label2 = [[UILabel alloc] initWithFrame:CGRectMake(85, 75, 70, 20)];
  41. label2.font = [UIFont systemFontOfSize:12];
  42. label2.textAlignment = NSTextAlignmentCenter;
  43.  
  44. label3 = [[UILabel alloc] initWithFrame:CGRectMake(165, 75, 70, 20)];
  45. label3.font = [UIFont systemFontOfSize:12];
  46. label3.textAlignment = NSTextAlignmentCenter;
  47.  
  48. label4 = [[UILabel alloc] initWithFrame:CGRectMake(245, 75, 70, 20)];
  49. label4.font = [UIFont systemFontOfSize:12];
  50. label4.textAlignment = NSTextAlignmentCenter;
  51.  
  52. [self addSubview:label1];
  53. [self addSubview:label2];
  54. [self addSubview:label3];
  55. [self addSubview:label4];
  56.  
  57. }
  58. return self;
  59. }
  60.  
  61. - (void)awakeFromNib
  62. {
  63. // Initialization code
  64. }
  65.  
  66. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  67. {
  68. [super setSelected:selected animated:animated];
  69.  
  70. // Configure the view for the selected state
  71. }
  72.  
  73. @end

【代码笔记】iOS-scrollerView里多个tableView加搜索框的更多相关文章

  1. [iOS微博项目 - 1.2] - 导航栏搜索框

    A.导航栏搜索框 1.需求 在“发现”页面,在顶部导航栏NavigationBar上添加一个搜索框 左端带有“放大镜”图标 github: https://github.com/hellovoidwo ...

  2. 【代码笔记】iOS-UIScrollerView里有两个tableView

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  3. 【代码笔记】iOS-实现网络图片的异步加载和缓存

    代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. se ...

  4. ios项目里扒出来的json文件

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...

  5. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  6. WWDC 2014 Session笔记 - iOS界面开发的大一统

    本文是我的 WWDC 2014 笔记 中的一篇,涉及的 Session 有 What's New in Cocoa Touch Building Adaptive Apps with UIKit Wh ...

  7. 【hadoop代码笔记】hadoop作业提交之汇总

    一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...

  8. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  9. <Python Text Processing with NLTK 2.0 Cookbook>代码笔记

    如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...

随机推荐

  1. HT for Web整合OpenLayers实现GIS地图应用

    HT for Web作为逻辑拓扑图形组件自身没有GIS功能,但可以与各种GIS引擎即其客户端组件进行融合,各取所长实现逻辑拓扑和物理拓扑的无缝融合,本章将具体介绍HT for Web与开发免费的Ope ...

  2. angularJs指令深度分析

    AngularJs的指令定义大致如下 angular.module("app",[]).directive("directiveName",function() ...

  3. C语言学习014:结构化数据类型

    struct的基本使用 #include <stdio.h> //定义数据结构 struct fish{ const char *name; const char *species; in ...

  4. [转]俞敏洪:我和马云就差了8个字... [来自: news.mbalib.com]

    我和马云差了 8 个字:越败越战,愈挫愈勇. 马云,我真的非常的佩服他,首先佩服他的是他跟我有同样的经历,我考了 3 年才考上了大学:他也是考了 3 年.我比他还要幸运一点,我考上的是北大的本科,马云 ...

  5. iOS阶段学习第一天笔记(Mac终端的操作)

    前言部分 原本从事的是.NET开发,一直在要不要转iOS 中犹豫徘徊,经过复杂的内心挣扎终于鼓起勇气辞职脱产学习iOS;希望通过四个月的 学习后能够拿到理想的薪资.以下是学习过程中的学习笔记,为了方便 ...

  6. C# POST Https请求的一些坑

    写在前面: 从上次,跟合作方的站点对接开始就产生了这个问题,当时用C#进行POST提交,总是会出现问题,找了很久发现对方的站点居然是TLS 1.2 的. 正文: 然而,在.NET FrameWork ...

  7. Delphi QC 记录

    各网友提交的 QC: 官方网址 说明 备注 https://quality.embarcadero.com/browse/RSP-12985 iOS device cannot use indy id ...

  8. 设置Xshell中支持中文

    执行echo $LANG命令输出的是当前的编码方式,执行locale命令得到系统中所有可用的编码方式.要让Xshell不显示乱码,则要将编码方式改为UTF-8. 在Xshell中[file]-> ...

  9. 调优Java virtual machine常见问题汇总整理

    数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:他代表的值就是数值本身:而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对象本身, ...

  10. UVA 12169 Disgruntled Judge 枚举+扩展欧几里得

    题目大意:有3个整数 x[1], a, b 满足递推式x[i]=(a*x[i-1]+b)mod 10001.由这个递推式计算出了长度为2T的数列,现在要求输入x[1],x[3],......x[2T- ...