#pragma mark - 数据源方法 返回分组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
#pragma mark - 数据源方法 返回每组的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section==0) {
return self.tencent.count;
}else{
return self.ali.count;
}
}
#pragma mark 返回每组内容
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:nil];
NSString *city=nil;
if (indexPath.section==0) {
city=self.tencent[indexPath.row];
}else{
city=self.ali[indexPath.row];
}
//设置主标题
cell.textLabel.text=city;
//设置图标
cell.imageView.image=[UIImageimageNamed:@"001.png"];
//设置副标题
cell.detailTextLabel.text=@"副标题";
//设置右边的箭头样式
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
#pragma mark添加title
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if (section==0) {
return @"腾讯";
}else{
return @"阿里巴巴";
}
}
//添加脚信息
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
if (section==0) {
return@"腾讯旗下产品系列";
}else{
return@"阿里旗下产品系列";
}
}
//UITableViewDelegate 设置每一行cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 80;
}
//显示索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
return @[@"a",@"b",@"b",@"c",@"d"];
}
//监听行
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//弹框让控制器充当代理
UIAlertView *alert=[[UIAlertViewalloc]initWithTitle:@"title"message:@"提示"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
// alert.tag=indexPath.row;
self.currentRow=indexPath.row;
self.currentSection=indexPath.section;
alert.alertViewStyle=UIAlertViewStylePlainTextInput;
//根据组和列获取lalbel的值
NSString *text=nil;
if(indexPath.section==0){
text=self.tencent[indexPath.row];
}else{
text=self.ali[indexPath.row];
}
//设置文本框的值
[alerttextFieldAtIndex:0].text=text;
//显示弹出框
[alertshow];
}
//alert点击了某个按钮
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==1) {
//根据tag获取
//获取第一个文本框输入的值
NSString *text=[alertView textFieldAtIndex:0].text;
if(self.currentSection==0){
self.tencent[self.currentRow]=text;
}else{
self.ali[self.currentRow]=text;
}
//刷新所有行数据
//[self.dataView reloadData];
NSIndexPath *path=[NSIndexPathindexPathForRow:self.currentRowinSection:self.currentSection];
//带动画刷新指定行数据
[self.dataViewreloadRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationLeft];
}
}
|