tableview使用

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

cell.textLable.text = @"hello";

删除模式

self.tableView.editing = YES; //开启删除模式

左划样式

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //样式定义
    return UITableViewCellEditingStyleInsert;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.dataSource removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
      //[self.tableView reloadData];
    } else if(editingStyle == UITableVIewCellEditingStyleInsert) {
      [self.listdata insertObject:@"" atIndex:indexPath.row];
      //[self.tableView reloadData];
      NSIndexPath *newPath= [NSIndexPath indexPatForRow:indexPath.row +1 inSection:indexPath.section];
      [self.tableView insertRowsAtIndexPath:@[newPath] withRowAnimation:UITableViewRowAnimationMiddle];
  }
}

移动单元格

-(BOOL) tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    //[self.dataList exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];
    id source = self.dataList[sourceIndexPath.row];
    [self.dataList removeObjectAtIndex:sourceIndexPath.row];
    [self.dataList insertObject:source atIndex:destinationIndexPath.row];
    [self.tableView reloadData];
}

你可能感兴趣的:(tableview使用)