我想在UITableViewCell
上显示“删除”按钮,就像我们在单元格上从右向左滑动一样。我需要点击单元格内的另一个按钮来显示此按钮。
到目前为止,我尝试了以下方法:
虽然#1没有显示,但按钮#2显示良好。但是我无法点击按钮,因为它超出了超视距的范围。
知道如何去做吗?
这就是我移动单元格内容的方式(此方法在我的自定义单元格类中。):
- (void)showCellDeleteButton {
if (self.isDeleteMode) {
return;
}
self.cellDeleteButton.hidden = NO;
self.isDeleteMode = YES;
[self disableDeleteItemButton];
[UIView animateWithDuration:0.3 animations:^{
CGRect cellFrame = self.frame;
cellFrame.origin.x -= 80.0;
self.frame = cellFrame;
} completion:nil];
}
这是我的删除按钮#2:
答案 0 :(得分:0)
你也可以这样做。 1.在单元格的内容视图中添加UIView,并根据您的要求设置相同宽度的单元格内容视图和设计。 2.然后将具有删除设计的按钮添加到单元格的内容视图中,而不是其他视图。 3.当您想要显示删除按钮时,只需将视图向左移动80点,不要移动单元格和单元格的内容视图。
答案 1 :(得分:0)
方法1: 我不认为你可以修改单元格的默认滑动手势。您只能启用或禁用手势。因此,这意味着您无法在单元格滑动时显示默认删除按钮。您可以做的是在单击按钮时使tableView可编辑,然后您可以显示删除按钮。例如
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Required data: {{name.tables[0].tabledata[1].grade.content}}</p>
</body>
<script>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = {
"tables":
[
{
"courseid": 8,
"userid": 14,
"userfullname": "bhavani Rayappanavar",
"maxdepth": 2,
"tabledata":
[
{
"itemname":
{
"class": "level1 levelodd oddd1 b1b b1t column-itemname",
"colspan": 7,
"content": "CategoryPhysics",
"celltype": "th",
"id": "cat_8_14"
},
"leader":
{
"class": "level1 levelodd oddd1 b1t b2b b1l column-leader",
"rowspan": 3
}
},
{
"itemname":
{
"class": "level2 leveleven item b1b column-itemname",
"colspan": 1,
"content": "Quizquiz",
"celltype": "th",
"id": "row_164_14"
},
"weight":
{
"class": "level2 leveleven item b1b itemcenter column-weight",
"content": "100.00 %",
"headers": "cat_8_14 row_164_14 weight"
},
"grade":
{
"class": "level2 leveleven item b1b itemcenter column-grade",
"content": "10.00",
"headers": "cat_8_14 row_164_14 grade"
},
"range":
{
"class": "level2 leveleven item b1b itemcenter column-range",
"content": "0–10",
"headers": "cat_8_14 row_164_14 range"
},
"percentage":
{
"class": "level2 leveleven item b1b itemcenter column-percentage",
"content": "100.00 %",
"headers": "cat_8_14 row_164_14 percentage"
},
"feedback":
{
"class": "level2 leveleven item b1b feedbacktext column-feedback",
"content": " ",
"headers": "cat_8_14 row_164_14 feedback"
},
"contributiontocoursetotal":
{
"class": "level2 leveleven item b1b itemcenter column-contributiontocoursetotal",
"content": "100.00 %",
"headers": "cat_8_14 row_164_14 contributiontocoursetotal"
}
},
{
"itemname":
{
"class": "level1 levelodd oddd1 baggt b2b column-itemname",
"colspan": 1,
"content": "NaturalCourse total",
"celltype": "th",
"id": "row_103_14"
},
"weight":
{
"class": "level1 levelodd oddd1 baggt b2b itemcenter column-weight",
"content": "-",
"headers": "cat_8_14 row_103_14 weight"
},
"grade":
{
"class": "level1 levelodd oddd1 baggt b2b itemcenter column-grade",
"content": "10.00",
"headers": "cat_8_14 row_103_14 grade"
},
"range":
{
"class": "level1 levelodd oddd1 baggt b2b itemcenter column-range",
"content": "0–10",
"headers": "cat_8_14 row_103_14 range"
},
"percentage":
{
"class": "level1 levelodd oddd1 baggt b2b itemcenter column-percentage",
"content": "100.00 %",
"headers": "cat_8_14 row_103_14 percentage"
},
"feedback":
{
"class": "level1 levelodd oddd1 baggt b2b feedbacktext column-feedback",
"content": " ",
"headers": "cat_8_14 row_103_14 feedback"
},
"contributiontocoursetotal":
{
"class": "level1 levelodd oddd1 baggt b2b itemcenter column-contributiontocoursetotal",
"content": "-",
"headers": "cat_8_14 row_103_14 contributiontocoursetotal"
}
}
]
}
],
"warnings":
[
]
};
});
</script>
</html>
方法2: 设计自己的自定义单元格,可以显示自定义按钮,看起来像默认。请参考以下链接。 https://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views