ios UIKit框架分析 第2天

来源:互联网 发布:excel表格导入数据库 编辑:程序博客网 时间:2024/05/16 14:00

1.UITableView

->@property(nonatomic,retain)UIView *tableFooterView用于动态实现上拉刷新加载更多得提示视图;参考:http://blog.csdn.net/wwwang89123/article/details/11663751

右侧索引字幕得颜色以及点击时候得背景颜色

@property(nonatomic,retain)UIColor *sectionIndexColorNS_AVAILABLE_IOS(6_0)UI_APPEARANCE_SELECTOR;                   // color used for text of the section index

@property(nonatomic,retain)UIColor *sectionIndexBackgroundColorNS_AVAILABLE_IOS(7_0)UI_APPEARANCE_SELECTOR;         // the background color of the section index while not being touched

@property(nonatomic,retain)UIColor *sectionIndexTrackingBackgroundColorNS_AVAILABLE_IOS(6_0)UI_APPEARANCE_SELECTOR;// the background color of the section index while it is being touched


->两个重要得数据源协议实现    电话簿快速查找的索引效果

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;                                                   // return list of section titles to display in section index view (e.g. "ABCD...Z#")

显示右边的索引字幕

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {     NSMutableArray *toBeReturned = [[NSMutableArray alloc]init];     for(char c = ‘A’;c<=‘Z’;c++)          [toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];    return toBeReturned; }


- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index; // tell table which section corresponds to section title/index (e.g. "B",1))

把右边的字幕和tableView的section关联起来,return的 count 就是滚到最顶端的section的index。

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {    NSInteger count = 0;     for(NSString *character in arrayOfCharacters)   {        if([character isEqualToString:title])        {                 return count;          }         count ++;    }     return 0; }


参考:http://blog.sina.com.cn/s/blog_6084f5880100ud6t.html


->UITableViewCell 的移动 插入 删除 标记等操作   参考:http://blog.csdn.net/duxinfeng2010/article/details/7725897


2.UILocalizedIndexedCollation 

-》UILocalizedIndexedCollation 管理数据源 实现tableview的索引搜索

参考:http://blog.csdn.net/developer_zhang/article/details/8904464

demon下载地址:http://download.csdn.net/detail/u010013695/5347923


// Provides the list of section titles used to group results (e.g. A-Z,# in US/English) 提供tableView的头部的内容 A - Z,#27个字母;

@property(nonatomic,readonly)NSArray *sectionTitles;

//设置Section的Header的值- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {        NSString *key = [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex:section];        return key;    }


@property(nonatomic,readonly)NSArray *sectionIndexTitles;  为tableView右侧的索引栏提供显示内容  a-z,#27个字母。


//设置表格的索引数组-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{    return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];    }


- (NSInteger)sectionForObject:(id)object collationStringSelector:(SEL)selector; //依据某个对象的字符串类型的属性 locaName的首字母 把该对象归入相应的section。--   把索引标题与tableView的section关联起来。

// Segregate the time zones into the appropriate arrays.for (ZYTimeZoneWrapper *timeZone in timeZonesArray) {        //根据timezone的localename,获得对应的时区的section numberNSInteger sectionNumber = [collation sectionForObject:timeZone collationStringSelector:@selector(localeName)];        NSLog(@"sectionNo:%d  localName is :%@",sectionNumber,timeZone.localeName);        //获得section的数组NSMutableArray *sectionTimeZones = [newSectionsArray objectAtIndex:sectionNumber];        //添加时区内容到section中[sectionTimeZones addObject:timeZone];}



- (NSInteger)sectionForSectionIndexTitleAtIndex:(NSInteger)indexTitleIndex;

// 根据点击的索引字母跳到相应的section- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{   return  [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index];}


- (NSArray *)sortedArrayFromArray:(NSArray *)array collationStringSelector:(SEL)selector;


     ZYTimeZoneWrapper * time1 = [[[ZYTimeZoneWrapper alloc]initWithName:@"你好"]autorelease];     ZYTimeZoneWrapper * time2 = [[[ZYTimeZoneWrapper alloc]initWithName:@"yong"]autorelease];     ZYTimeZoneWrapper * time3 = [[[ZYTimeZoneWrapper alloc]initWithName:@"飞"]autorelease];     ZYTimeZoneWrapper * time4 = [[[ZYTimeZoneWrapper alloc]initWithName:@"qing"]autorelease];     ZYTimeZoneWrapper * time5 = [[[ZYTimeZoneWrapper alloc]initWithName:@"超"]autorelease];    NSArray * temp = [NSArray arrayWithObjects:time1,time2,time3,time4,time5,nil];        NSArray * sortA = [[UILocalizedIndexedCollation currentCollation] sortedArrayFromArray:temp collationStringSelector:@selector(name)];    NSLog(@"%@",[sortA description]);

依据对象的字符串类型的属性name的首个字母(中文则为拼音的首个字符)进行排序 默认顺序为(a - z);


->索引栏上显示搜索的标志

代码如下:

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{    return [[NSArray arrayWithObject:UITableViewIndexSearch] arrayByAddingObjectsFromArray:[[UILocalizedIndexedCollation currentCollation] sectionIndexTitles]];}
效果图如下:A字母上的标识



0 0
原创粉丝点击