简体   繁体   中英

Prevent dragging of cell to the left in iOS7 tableview editing mode

Screenshot below shows one tableview cell in editing mode after swiping to the left on the row. While in editing mode I can hold the cell and drag further to the left again which reveals this white space (bouncy effect when I let go). I'm setting each cell's background image as follows:

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CellBG.jpg"]];

I have 2 questions.

  1. Is it possible to prevent this extra dragging so this white area will never be seen? Would like the same behaviour as the iOS7 weather app for example.
  2. Also, any idea why there is thin white line under the delete button?

Thanks

截图

  1. Is it possible to prevent this extra dragging so this white area will never be seen?

Yes. Put the image on the UITableView 's background. Not on the cell. Because if you put the image background on a cell and when you horizontally swap a cell to delete, that cell will move. That is to say the image background will also move. But if you put it on the UITableView , it will not move with the swap. Remember to set UITableView and UITableViewCell 's background color to be clear color.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseIdentifier"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBackground.png"]];
    imageView.frame = CGRectMake(0, kCellHeight*indexPath.row, 320, cell.frame.size.height);
    [tableView addSubview:imageView];
    [tableView sendSubviewToBack:imageView];
    return cell;
}

2.Also, any idea why there is thin white line under the delete button?

I think that is Apple's little bug. As you can also find it in the weather app. So never mind that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM