//将tableview的原点归到(0,0);
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 ? YES : NO) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
//设置tableview的位置
table = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, screen_width, screen_height-64) style:0];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screen_width, screen_height)];
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"beijing.png"]];
table.backgroundView = view;
[self.view addSubview:table];
//代理
table.delegate = self;
table.dataSource = self;
//设置cell是否可以点击
table.allowsSelection = YES;
//隐藏滚动条
table.showsHorizontalScrollIndicator = NO;
table.showsVerticalScrollIndicator = NO;
//表头颜色
table.sectionIndexColor = [UIColor lightGrayColor];
#pragma mark------UITableViewDataSource,UITableViewDelegate-------
//设置区数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 26;
}
//设置区的高度
- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section
{
return 50;
}
//每组的行数
-(NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
NSArray *array = pinyinArray[section];
return array.count ;
}
//索引
-(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return idArray;
}
//cell内容的设置
-(UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
return cell;
}
//区头的设置
- (UIView *)tableView:(UITableView *)tableViewviewForHeaderInSection:(NSInteger)section{
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, screen_width, 50)];
label.text = [dataSouce[section] uppercaseString];
label.backgroundColor = [UIColor colorWithRed:157/255.0 green:157/255.0 blue:157/255.0 alpha:0.7];
return label;
}
//cell点击事件
-(void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}