UITableView Cell Index和数据库的匹配套用
来源:互联网 发布:软件著作权操作说明书 编辑:程序博客网 时间:2024/05/16 19:23
前几天纠结自己不怎么会使用UItableview 现在整理如下
UItableview 要想实现完整的内容,要遵循两个协议,除此之外,设置Uitableview 在这个之前,已经自定义一个类uitableview的设置属性,所以,直接展示几个关键的方法。
[self.tableView setSectionHeaderHeight:40.0];
[self.tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"beijing.png"]]];
[self.tableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"dividing-line@2x.png"]]];
[self.tableView setSectionIndexColor:[UIColor brownColor]];
以上是所有相关的tableview的设置,在这里,在H里面将tableview设置为了属性,好处,方便使用调用(在多个类中),第二个:减少了relese 的麻烦
_buShouArray=[[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17", nil];
_bsMinCh=[[NSArray alloc]initWithObjects:@"笔画一",@"笔画二",@"笔画三",@"笔画四",@"笔画五",@"笔画六",@"笔画七",@"笔画八",@"笔画九",@"笔画十",@"笔画十一"@"笔画十二",@"笔画十三",@"笔画十四",@"笔画十五",@"笔画十六",@"笔画十七", nil];
以下是必须遵守的两个协议:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_headerArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * inidentifier=@"cell";
UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:inidentifier];
if (cell==nil) {
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:inidentifier]autorelease];
}
strArr=[_headerArray objectAtIndex:indexPath.section];
pysStr=[[Pinyin selectPinyinByType:strArr]objectAtIndex:indexPath.row];
cell.textLabel.text=pysStr.pinyin;
return cell;
}
自定义UItableview的每个分区的header
//每个分区的头部
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [_headerArray objectAtIndex:section];
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIButton * headButton=[Utility addButtonWithType:UIButtonTypeCustom andTag:9 andFrame:CGRectMake(0, 0, 320, 40) andTitle:nil andBackgroundImage:[UIImage imageNamed:@"pinyin@2x.png"] andFuction:nil andDelegate:self andView:self.tableView];
[headButton.titleLabel setTextAlignment:NSTextAlignmentLeft];
UILabel * label =[Utility addLabelWithTitle:[_headerArray objectAtIndex:section] andFrame:CGRectMake( 13,-15, 100, 70) andView:headButton];
[label setTextAlignment:NSTextAlignmentLeft];
label.textColor=[UIColor brownColor];
label.font=[UIFont fontWithName:@"Arial" size:30.0];
label.backgroundColor =[UIColor clearColor];
return headButton;
}
设置每个分区的内容
//设定每个分区的行数以及行数的显示内容
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString * pyStr =[_headerArray objectAtIndex:section];
return [[Pinyin selectPinyinByType:pyStr]count];
}
在这里面,实质上展示出的是部分的内容因为要和data相关Pinyin就是导出database的类的名称,从database中根据type属性选择相关的字节,展示在每个section里面。
设置在右部展示的index
-(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return _headerArray;
}
相关联接下来的另外一个tableview,用这个方法关联
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RootDetailViewController * chaZi=[[RootDetailViewController alloc]init];
NSString * stAr=[_headerArray objectAtIndex:indexPath.section];
Pinyin * bss=[[Pinyin selectPinyinByType:stAr]objectAtIndex:indexPath.row];
chaZi.strText=bss.pinyin;
//NSLog(@"bss=%@",bss.title);
[self.navigationController pushViewController:chaZi animated:YES];
[chaZi release];
}
- UITableView Cell Index和数据库的匹配套用
- UITableView和UICollectionView的cell重用问题
- UITableView刷新指定的section和cell
- UITableView的Cell排序
- UITableView cell的重用
- UITableView cell的重复使用
- UITableView 的 自定义cell
- UITableView的自定义cell
- 关于UITableView和cell的自定义和技巧
- DatePickerDialog的使用和套用
- UITableViewCell - UITableView中cell的边框和背景
- UITableViewCell - UITableView中cell的边框和背景 .
- UITableViewCell - UITableView中cell的边框和背景
- UITableViewCell - UITableView中cell的边框和背景
- UITableViewCell - UITableView中cell的边框和背景
- UITableView cell上的button和label问题
- Masonry 和 UITableView-FDTemplateLayoutCell 实现自适应高度的Cell
- 第六天,UITableView,和cell的基础介绍
- NFC基础
- iOS后向兼容:如何发现过期接口
- hdu 1151 Cable master (好坑的精度。。。)
- shell脚本参数
- 线程间互斥锁
- UITableView Cell Index和数据库的匹配套用
- (7)哈希表的链地址法实现
- VS2010解决方案转换到VS2008
- 继承ViewGroup研究(汇总) 一、二、三
- C语言运算符的优先级
- 安装tengine-1.5.0,两个小白的故事
- WM_COPYDATA 消息实现进程间通信
- Linux查看磁盘/硬盘各分区的UUID(GUID)
- SRM 586 DIV2 250