【发布时间】:2011-09-01 05:59:27
【问题描述】:
我有一个可编辑的 UITableView。当我的用户重新排列单元格时,我希望能够更新表格视图,因为当我重新排列底部单元格并将其插入中间时,我遇到了一个有趣的情况。它会产生不需要的效果,因为底行是圆形的,而中间行不应该是圆形的。我怎样才能防止这种情况发生?
为了实现这种外观,我必须设置每个UITableViewCell 的backgroundView。顶部和底部使用的图像与中间的图像不同。
更新:
我不确定我是否遗漏了任何案例,因为重新订购时图像仍然混乱。
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"];
}
}
【问题讨论】:
-
您不应该在
imageNamed中使用@2x 后缀。它会在需要时自动添加。 -
是否可以通过舍入表格视图的角而不是内部单元格来回避问题?它的外观和行为会有所不同,但它会是对您应用的任何样式规则的另一种解读吗?
-
tableview是圆角的,我只是使用自定义图形。
标签: iphone objective-c cocoa-touch uitableview