【发布时间】:2015-12-01 06:03:04
【问题描述】:
我想更改 uitableview 单元格的滑动按钮图像。我已经搜索过了,但没有得到想要的结果。我用过这段代码:
- (void)willTransitionToState:(UITableViewCellStateMask)state{
[super willTransitionToState:state];
if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
for (UIView *subview in self.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
[deleteBtn setImage:[UIImage imageNamed:@"delete.png"]];
[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
}
}
}
}
但这在 iOS 9 中不起作用。请建议我如何在 iOS 9 中实现这一点。
如果我使用了此代码,那么它可以正常工作,但图像设置不正确:
[[UIButton
appearanceWhenContainedIn:[TableViewCell class], nil]
setImage:[UIImage imageNamed:@"Delete-notification.png"] forState:UIControlStateNormal];
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button 1");
}];
return @[button];
}
]1
提前致谢!
【问题讨论】:
-
@FeminaBrahmbhatt 我也用过这个但没用:(
标签: ios objective-c uitableview ios9.1