1. 程式人生 > >UITableView 帶右側索引以及Section

UITableView 帶右側索引以及Section

//右邊索引 位元組數(如果不實現 就不顯示右側索引)
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    return sectionName;
}

//section (標籤)標題顯示
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [sectionName objectAtIndex:section];
}

//標籤數
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return sectionName.count;
}

// 設定section的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

//點選右側索引表項時呼叫
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    NSString *key = [sectionName objectAtIndex:index];
    NSLog(@"sectionForSectionIndexTitle key=%@",key);
    if (key == UITableViewIndexSearch) {
        [tableViewProj setContentOffset:CGPointZero animated:NO];
        return NSNotFound;
    }
    return index;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,320, 400)];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(8, 13, 70, 20)];
    title.text = [sectionName objectAtIndex:section];
    title.textColor=[UIColor whiteColor];
    title.font = [UIFont systemFontOfSize:15];
    title.textAlignment= NSTextAlignmentCenter;
    title.backgroundColor = Rgb2UIColor(233,82,62);
    [view addSubview:title];
    return view;
}


// 設定cell的高度
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        CGSize size = CGSizeMake(215,2000);
        CGSize labelsize = [[detailArr objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
        CGFloat height = labelsize.height+10;
        if (height>30) {
            return height;
        }
    }
    return 30;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 0)
    {
        return detailArr.count;
    }else
    {
        return 1;
    }
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DetailViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailViewCell" forIndexPath:indexPath];
    if (indexPath.section==0) {
        cell.title.text = [nameArr objectAtIndex:indexPath.row];
        cell.detaillab.text = [detailArr objectAtIndex:indexPath.row];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

相關推薦

UITableView 右側索引以及Section

//右邊索引 位元組數(如果不實現 就不顯示右側索引) - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {     return sectionName; } //section (標

UITableview右側索引以及按名字排序

UITableview右側索引 右側索引功能是iOS很常見的功能,在通訊錄就得到了完美應用,在說這個功能之前,我們首先了解一個按首字母或者漢字拼音首字母分組排序索引的類。它能夠根據地區來生成與之對應區域索引標題。不需要直接建立它的物件,我們可以通過 UILocalizedIndexed

自定義UITableView右側索引

// 右邊索引的標題陣列 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { NSMutableArray *array = [NSMutableArray array]; for(int section='A';s

lucene創建索引以及索引文件合並

dex null menu test alt tor document oid stand 1 package test; 2 3 import java.io.File; 4 import java.io.IOException; 5 import

Sql Server 索引以及頁和區

順序存儲 alt cluster 思考 文檔 數據存儲 div 數據頁 博客 索引(Index),相信大家都知道就是給表中的數據添加了一個目錄,使我們可以快速檢索到我們想要的數據,但這個目錄是什麽?SqlServer又是如何管理的?要搞明白這些,我們就要先了解sqlserv

Mysql-如何正確的使用索引以及索引的原理

缺失 目的 連續 註意 例子 查點 MIP 錯誤 warn 一、 介紹 二、 索引的原理 三、 索引的數據結構 四、 聚集索引與輔助索引 五、 MySQL索引管理 六、 測試索引 七、 正確使用索引 八、 聯合索引與覆蓋索引 九、 查詢優化神器-expl

mysql創建索引以及索引的理解

bsp 空間 select table 創建表 類型 但是 排除 假設 創建索引是指在某個表的一列或多列上建立一個索引,以便提高對表的訪問速度。創建索引有3種方式,這3種方式分別是創建表的時候創建索引、在已經存在的表上創建索引和使用ALTER TABLE語句來創建索引。本節

mysql8使用自全文索引中文分詞)

lte not null incr sdh values 自帶 var 科學 全文索引 修改配置文件:vim /etc/my.cnf [mysqld] ngram_token_size=2 創建表: create table test( id int(11) not nu

oracle資料庫建立索引以及簡單優化sql語句

Oracle 建立索引及SQL優化 資料庫索引: 索引有單列索引 複合索引之說 如何某表的某個欄位有主鍵約束和唯一性約束,則Oracle 則會自動在相應的約束列上建議唯一索引。資料庫索引主要進行提高訪問速度。 建設原則:  1、索引應該經常建在Where 子句經常用到的列上。如

mysql索引以及慢SQL優化記錄【轉慕課】

原文大家可以參考下連結 mysql索引介紹以及慢SQL優化 索引介紹 【略】 SQL優化說明 執行計劃explain的使用不做說明。 1.最左字首匹配原則,非常重要的原則,mysql會一直向右匹配直到遇到範圍查詢(>、<、between、like

向量索引以及矩陣索引

*%向量的表示 v=[1 2 4 6 8] %選取向量中的元素 v(2) %行向量轉換為列向量 w=v.' %存取向量的前三個元素 v(1:3) %存取第三個到最後一個元素 v(3:end) %選取步長為2從前到最後的元素 v(1:2:end) %從v中挑選第一

變數路由以及GET、POST請求獲取

from flask import render_template from flask import Flask from flask import Markup from flask import abort, redirect import flask from fla

正確建立索引以及最左字首原則

例項分析 通過例項理解單列索引、多列索引以及最左字首原則 例項:現在我們想查出滿足以下條件的使用者id: mysql>SELECT `uid` FROM people WHERE lname`=‘Liu’ AND `fname`=‘Zhiqun’ AND `age`=26 因為我們不想掃描整表,故考慮

qchart 柱狀圖頂端數字顯示以及tooltip

最近做個小介面,之前有用過qchart雖然比qwt好用一點,但是bug還是有那麼些,總體還行吧。當前想實現的功能就是講資料以柱狀圖的形式實現,並且在柱狀圖的頂部顯示每個柱狀圖的資料,同時提供Tooltip功能。那麼就開始說說如何建立吧。 1、首先定義實現qchart物件 m_char=new

資料庫索引以及索引的實現(B+樹介紹,和B樹,區別)

索引 索引是提高資料庫表訪問速度的方法。 分為聚集索引和非聚集索引。 聚集索引:對正文內容按照一定規則排序的目錄。 非聚集索引:目錄按照一定的順序排列,正文按照另一種順序排列,目錄與正文之間保持一種對映關係。 把資料庫索引比作字典查詢索引, 聚集索引

MS SQL 查詢資料庫中所有索引以及對應的表字段 SQL Server Profiler效能跟蹤

新專案上線,需要對庫裡的表進行相關索引檢查。這兒首先需要檢視一下庫裡的表那些有索引,然後用SQL Server Profiler進行跟蹤,檢查SQL語句效能,查詢頻率等。 查詢庫裡所有索引相關資訊這兒給出一個SQL,使用了CTE查詢: with temp as(

elasticsearch 建立索引以及設定相關 field屬性

package com.weibo.dip.kte; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.i

MongoDB 建立基礎索引、組合索引、唯一索引以及優化

一、索引 MongoDB 提供了多樣性的索引支援,索引資訊被儲存在system.indexes 中,且預設總是為_id建立索引,它的索引使用基本和MySQL 等關係型資料庫一樣。其實可以這樣說說,索引是凌駕於資料儲存系統之上的另一層系統,所以各種結構迥異的儲存

資料庫的索引以及在哪些列上建立索引

要比使用非聚集索引速度快得明顯的多;而資料量如果很大的話,如10萬以上,則二者的速度差別不明顯。    3、使用聚合索引內的時間段,搜尋時間會按資料佔整個資料表的百分比成比例減少,而無論聚合索引使用了多少個:    select gid,fariqi,neibuyonghu,reader,title from

UITableView設定快速索引字型顏色

當UITableView的分組較多的時候,經常會用到快速索引。 預設的快速索引是不允許設定的,但是還是有些牛人找到了Apple隱藏的介面 - (void)viewDidLayoutSubviews { [super viewDidLayo