带索引的tableView

一,效果图。

二,工程图。

三,代码。



RootViewController.h




#import <UIKit/UIKit.h>



@interface RootViewController : UIViewController


<UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,UISearchBarDelegate>


{


UITableView * tableview;


NSMutableArray * Aarray;


UISearchBar * searchBar;


UISearchDisplayController *searchControl;


}


@end


复制代码


复制代码




RootViewController.m



复制代码


复制代码


#import "RootViewController.h"



@interface RootViewController ()



@end



@implementation RootViewController



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil


{


self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];


if (self) {


// Custom initialization


}


return self;


}



- (void)viewDidLoad


{


[super viewDidLoad];


// Do any additional setup after loading the view.



//初始化背景图


[self initBackGroundView];


}


#pragma -mark -functions


-(void)initBackGroundView


{


Aarray = [[NSMutableArray alloc] initWithObjects:@"+",@"我",@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#",nil];



//tableView


tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460-44-10-10-20) style:UITableViewStylePlain];


tableview.tag = 101;


tableview.delegate = self;


tableview.dataSource = self;


[self.view addSubview:tableview];



//searchView


searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];


tableview.tableHeaderView = searchBar;


searchBar.showsScopeBar = YES;


searchBar.placeholder = @"在全部关注中搜索...";



//搜索的时候会有左侧滑动的效果


searchControl = [[UISearchDisplayController alloc]initWithSearchBar:searchBar contentsController:self];


searchControl.delegate = self;


searchControl.searchResultsDataSource = self;


searchControl.searchResultsDelegate = self;




}


#pragma -mark -searchbar


-(void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope


{


;


}


#pragma -mark -UITableViewDelegate


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView


{


return 2;


}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section


{


if (section == 0) {


return 1;


}


return 100;


}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath


{


return 40.0;


}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


{


NSString * strID = @"ID";


UITableViewCell * cell = [tableview dequeueReusableCellWithIdentifier:strID];


if (cell == nil) {


cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:strID];


}



if (indexPath.section == 0 && indexPath.row == 0) {


cell.textLabel.text = @"找朋友";


}else if(indexPath.section ==1 && indexPath.row == 0){


cell.textLabel.text=@"row";


}


return cell;


}



-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section


{


if (section == 1) {


return @"我的资料";


}


return nil;


}


-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView


{


return [NSArray arrayWithObjects:UITableViewIndexSearch,@"+",@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#", nil];


}



- (void)didReceiveMemoryWarning


{


[super didReceiveMemoryWarning];


// Dispose of any resources that can be recreated.


}


复制代码

带索引的tableView的更多相关文章

  1. jQuery仿3D旋转木马效果插件(带索引按钮)

    项目中需要用到旋转木马效果,但是我在网上找的插件,基本都是不带按钮或者只是带前后按钮的,而项目要求的是带索引按钮,也就是说有3张图片轮播,对应的要有3个小按钮,点击按钮,对应的图片位于中间位置.于是就 ...

  2. Android带索引联系人列表

    网上Android联系人列表的样例也非常多,都和微信的联系人差点儿相同,因为项目用到了联系人列表索引功能(产品把字母item给去掉了),只是也还是好实现.这里我也来分享分享我的实现,免得以后忘了.那先 ...

  3. List带索引的常用方法,以及集合的三种遍历

    package cn.learn.collection.List; import com.sun.source.tree.NewArrayTree; import java.util.ArrayLis ...

  4. 【代码笔记】iOS-带索引的tableView

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

  5. Python3基础 list(enumerate()) 将一个列表的每一个元素转换成 带索引值的元组

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  6. Python3基础 list enumerate 将列表的每个元素转换成 带索引值的元组

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  7. ngFor 循环带索引

    *ngFor="let item of userList,let i = index"   或者 *ngFor="let item of userList index a ...

  8. C# 数组排序带索引

    想到了两种方法来实现,分别利用了List.Sort()和Dictionary.OrderBy()方法,代码如下: , , , , , , , , , }; //List.Sort() List< ...

  9. 3D游戏引擎设计 实时计算机图形学的应用方法 第2版 pdf 带索引书签目录

    3D游戏引擎设计  实时计算机图形学的应用方法  第2版 目录 第1章 概述1.1 图形硬件和游戏发展史1.2 本书版本与软件发展史1.3 章节导读 第2章 图形系统2.1 基础知识2.1.1 坐标系 ...

随机推荐

  1. linux的fork()函数-进程控制

    进程作为构成系统的基本细胞,不仅是系统中独立活动的实体,而且是独立竞争资源的基本实体.它要经历创建.执行.等待.终止等一系列过程. 一.fork入门知识(转载) 一个进程,包括代码.数据和分配给进程的 ...

  2. Linux必看书籍

    <鸟哥的Linux私房菜:基础学习篇(第三版)> <鸟哥的Linux私房菜——服务器架设篇> <高性能Linux服务器构建实战> <实战Nginx:取代 Ap ...

  3. 机器学习笔记(十)EM算法及实践(以混合高斯模型(GMM)为例来次完整的EM)

    今天要来讨论的是EM算法.第一眼看到EM我就想到了我大枫哥,EM Master,千里马.RUA!!!不知道看这个博客的人有没有懂这个梗的. 好的,言归正传.今天要讲的EM算法,全称是Expectati ...

  4. js-取值&赋值-获取某标签某属性的值

      js 取值&赋值-获取某标签某属性的值 CreateTime--2016年10月16日16:35:34 Author:Marydon 1.取值 //方法一 //自定义属性必须用getAtt ...

  5. JSTL中c:forEach循环里的值的substr操作及对String操作的常用API

    <c:forEach items="${dataList}" var="item" varStatus="itemStatus"> ...

  6. EditPlus破解版|很不错的编辑器

    Windows自带的notepad,功能一般.editplus,很值得推荐的编辑器! 注册秘钥: 用户名:www.dayanzai.me序列号:D2C86-E97A0-BF376-FDC33-27C1 ...

  7. Spring Boot 集成 GRPC

    代码地址如下:http://www.demodashi.com/demo/14110.html 一.背景 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring ...

  8. JavaScript中的闭包(closure)

    闭包的特性 1.函数嵌套函数 2.函数内部可以引用外部的参数和变量 3.参数和变量不会被垃圾回收机制回收  闭包的缺点就是常驻内存,会增大内存使用量,使用不当很容易造成内存泄露,主要用于私有的方法和变 ...

  9. MySQL-事务隔离级别设置

    加锁研究:http://www.cnblogs.com/JohnABC/p/4377529.html 先了解下 第一类丢失更新.脏读.不可重复读.幻读.第二类丢失更新 第一类丢失更新 撤销一个事务时, ...

  10. java.lang.UnsupportedClassVersionError: org/hibernate/SessionFactory : Unsupported major.minor version 52.0

    问题: 在学习hibernate的过程中,涉及导入jar包的问题,写该文的时候是从官网下载的最新的hibernate的jar包hibernate-release-5.2.10.Final .在测试时, ...