gpt4 book ai didi

iphone - 当用户重新排列单元格时,如何刷新 UITableView?

转载 作者:行者123 更新时间:2023-12-03 20:45:45 26 4
gpt4 key购买 nike

我有一个可编辑的 UITableView。当我的用户重新排列单元格时,我希望能够更新表格 View ,因为当我重新排列底部单元格并将其插入中间时,我遇到了一个有趣的情况。它会产生不需要的效果,因为底行是圆形的,而中间行不应该是圆形的。如何防止这种情况发生?

enter image description here

为了实现这种外观,我必须设置每个 UITableViewCellbackgroundView。顶部和底部的图像使用与中间的图像不同的图像。

更新:

我不确定是否遗漏了任何案例,因为重新排序时图像仍然困惑。

for (NSIndexPath* visibleIndexPath in tableView.indexPathsForVisibleRows) {
UITableViewCell* cell = [tableView cellForRowAtIndexPath:visibleIndexPath];

//Top moving to middle rows
if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row != sectionRows - 1) {
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddle55@2x.png"];
}
//Top moving to bottom
else if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row == sectionRows - 1) {
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablebottom55@2x.png"];
}
//Top moving to top
else if (sourceIndexPath.row == 0 && proposedDestinationIndexPath.row == 0) {
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tabletop55@2x.png"];
}
//Middle moving to top
else if (sourceIndexPath.row != 0 && sourceIndexPath.row != sectionRows -1 && proposedDestinationIndexPath.row == 0)
{
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tabletop55@2x.png"];
}
//Middle moving to bottom
else if (sourceIndexPath.row != 0 && sourceIndexPath.row != sectionRows -1 && proposedDestinationIndexPath.row == sectionRows - 1)
{
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablebottom55@2x.png"];
}
//Middle moving to middle
else if (sourceIndexPath.row != 0 && sourceIndexPath.row != sectionRows -1 &&
proposedDestinationIndexPath.row != sectionRows -1 && proposedDestinationIndexPath.row !=0)
{
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddle55@2x.png"];
}
//Bottom moving to top
else if (sourceIndexPath.row == sectionRows - 1 && proposedDestinationIndexPath.row == 0)
{
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tabletop@2x.png"];
}
//Bottom moving to middle
else if (sourceIndexPath.row == sectionRows - 1 && proposedDestinationIndexPath.row != 0 && proposedDestinationIndexPath.row != sectionRows - 1)
{
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddle@2x.png"];
}
//Bottom moving to bottom
else if (sourceIndexPath.row == sectionRows - 1 && proposedDestinationIndexPath.row == sectionRows - 1)
{
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablebottom@2x.png"];
}
}

最佳答案

好吧,您只需更改已更改单元格的背景 View ,就像在 tableview:cellForRowAtIndexPath: 中所做的那样。

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
//The rest of your stuff you need to do

for (NSIndexPath* visibleIndexPath in self.tableView.indexPathsForVisibleRows) {
UITableViewCell* visibleCell [self.tableView cellForRowAtIndexPath:visibleIndexPath];
if (visibleIndexPath.row == 0) ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tabletop55.png"];
else if (visibleIndexPath.row == [self tableView:tableView numberOfRowsInSection:visibleIndexPath.section) {
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablebottom55.png"];
}
else ((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"tablemiddile55.png"];
}
}

关于iphone - 当用户重新排列单元格时,如何刷新 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7266568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com