我想在单击按钮时滑动单元格。我成功刷了手机。但我想滑动单元格中的按钮。我的代码是
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleCell";
SimpleCell *cell = (SimpleCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
SimpleCell *cekks=[[SimpleCell alloc]init];
cekks.scrollButton.alpha =0.0;
NSString *titleString;
UIButton *sender = [[UIButton alloc]init];
//[sender setBackgroundImage:[UIImage imageNamed:@"swipe.png"] forState:UIControlStateNormal];
sender.tag = indexPath.row;
titleString =@"Send A Gift";
UITableViewRowAction *sendAGift = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:titleString handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// [self deleteMail:[NSArray arrayWithObject:indexPath]:YES];
}];
[sendAGift setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"swipe.png"]]];
return @[sendAGift];
}
我认为你的班级SimpleCell
应包含 UIButton,以便正确执行重用。
如果你创建一个自定义的,会更简单UITableViewCell
包含单元格上的所有 UI 操作,并在单元格内操作它们,而不是在UITableView
itself.
让我们看一个例子:
这是 customCell.h 文件:
@interface customCell : UITableViewCell {
UIButton *buttonSwipe;
}
@end
这是 customCell.h 文件:
#import "customCell.h"
@implementation customCell
- (instancetype) initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
}
return self;
}
- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self commonInit];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
}
- (void) commonInit {
buttonSwipe = [UIButton... // Initialize here your button
[buttonSwipe addTarget:self action:@selector(swipeCell:) forControlEvents:UIControlEventTouchUpInside];
}
- (void) swipeCell {
// Embed here the code that makes the effect of swipe the cell.
}
这是一个未经测试的快速解决方法,带有一些预定义的代码,但我认为如果您想让单元格滑动,这是一个有效的示例用你自己的代码.
但如果您想要更快的方式,我建议您访问克里斯·温德尔和他的SWTableViewCell
on GitHub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)