滑动单元格以删除时如何将单元格向左移动

时间:2014-07-07 10:41:46

标签: ios uitableview swipe

我是iOS开发的新手。 当我添加代码以支持在单元格中删除滑动时,我发现了一个问题,如下图所示。 当我滑动时,如何更多地移动细胞?

enter image description here

我的代码:

        // Override to support conditional editing of the table view.
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return YES;
    }

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView setEditing:YES animated:YES];
        return UITableViewCellEditingStyleDelete;
    }



    // Override to support editing the table view.
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            // Delete the row from the data source
            [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }
    }

    - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return @"删除";
    }

谢谢!

@Retro我在

下添加了cellForRowAtIndexPath方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *reuseIdentifier = @"cell";
    MainTableViewCell *cell = (MainTableViewCell *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier forIndexPath:indexPath];

    NSDictionary *data = [dateArray objectAtIndex:indexPath.row];

    cell.titleLabel.text = [data objectForKey:@"Title"];
    cell.dateLabel.text = [data objectForKey:@"Date"];


    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *past = [formatter dateFromString:[data objectForKey:@"Date"]];

    NSTimeInterval distance = [past timeIntervalSinceNow];
    NSInteger iDat = distance / ( 86400 ) ;
    NSString *distanceString = [NSString stringWithFormat:@"%d", (iDat < 0 ? -1 * iDat : iDat)];

    if (iDat < 0) {
        cell.daysLabel.textColor = [UIColor blueColor];
    } else {

    }
    cell.daysLabel.text = distanceString;

    cell.index = indexPath.row;

    return cell;
}

0 个答案:

没有答案