iOS —— UITableView 常用API

来源:互联网 发布:java大视频断点续传 编辑:程序博客网 时间:2024/05/22 12:37
COMMAND+SHIFT+0  API分享

单元格常用属性:

accessoryType    右侧小按钮样式backgroundColor  单元格背景颜色textLabel.text  单元格显示内容detailTextLabel.text  单元格副标题(如果UITableViewCellStyleDefault的时候,不显示detailTextLabel)detailTextLabel.textColor  副标题颜色imageView.image  添加图片(只读)contentView  自定义添加单元格内容cell.textLabel.highlightedTextColor  单元格选中状态的字体颜色
   //设置行高    table.rowHeight = 40;    //设置表格线的样式    table.separatorStyle=UITableViewCellSeparatorStyleSingleLine;    //设置表格线的颜色    table.separatorColor = [UIColor redColor];
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    static NSString *cellIdentifier = @"cell";    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];    if(cell == nil){        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];    }    cell.textLabel.text = [[[app.mDataList objectAtIndex:indexPath.row] componentsSeparatedByString:@","] objectAtIndex:0];    cell.detailTextLabel.text = [[[app.mDataList objectAtIndex:indexPath.row] componentsSeparatedByString:@","] objectAtIndex:1];    return cell;}-(void)edit{    BOOL isEdition = !self.mTableView.editing;    [self.mTableView setEditing:isEdition];}-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{    return YES;}-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{    return UITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;}-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{    return YES;}
//移动row时调用方法-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{    if(sourceIndexPath!=destinationIndexPath){        id object = [app.mDataList objectAtIndex:sourceIndexPath.row];        [object retain];        [app.mDataList removeObjectAtIndex:sourceIndexPath.row];        if (sourceIndexPath.row>app.mDataList.count) {            [app.mDataList addObject:object];        }else{            [app.mDataList insertObject:object atIndex:destinationIndexPath.row];        }    }}-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{    //数据处理    [app.mDataList removeObject:[self.mDeletedList objectAtIndex:indexPath.row]];}
//判断点击row的方式是否是编辑模式-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    if (tableView.editing == NO) {        NextViewController *nextVC = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];        nextVC.delegate = self;        [self.navigationController pushViewController:nextVC animated:YES];    }else{//数据处理        [self.mDeletedList addObject:[app.mDataList objectAtIndex:indexPath.row]];    }}
//编辑模式下,删除按钮所调方法-(void)finishDelete{    [app.mDataList removeObjectsInArray:self.mDeletedList];    [self.mTableView reloadData];    self.mTableView.editing = NO;} //滑动删除-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];}
//当TableView将要呈现的时-(void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:YES];    [self.mTableView reloadData];}
//row高度- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    if (indexPath.row==0) {        return tableView.rowHeight;    }else{        return tableView.rowHeight*2;    }}- (NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView{    return ABC;}
//自定义TableVIew 内容    static NSString *cellIdetifier = @"mycell";    myCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdetifier];    if(cell==nil){        cell = [[[NSBundle mainBundle] loadNibNamed:@"myCell" owner:self options:nil] lastObject];    }

0 0
原创粉丝点击