作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在项目中使用以下代码:
if([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
这在 iOS 5 和 6 上运行良好。但在 iOS 7 上它总是返回 NO。
谁能告诉我这是 iOS 7 的问题还是我做错了什么?
谢谢!
最佳答案
这是我供人们构建的骇人听闻的未完成实现。
这应该适用于 iOS6-- 和 iOS7。
显然,此代码位于您的子类 UITableViewCell 中。
-(void)willTransitionToState:(UITableViewCellStateMask)state{
NSLog(@"EventTableCell willTransitionToState");
[super willTransitionToState:state];
if((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask){
[self recurseAndReplaceSubViewIfDeleteConfirmationControl:self.subviews];
[self performSelector:@selector(recurseAndReplaceSubViewIfDeleteConfirmationControl:) withObject:self.subviews afterDelay:0];
}
}
-(void)recurseAndReplaceSubViewIfDeleteConfirmationControl:(NSArray*)subviews{
NSString *delete_button_name = @"button_panorama_no_arrow";
for (UIView *subview in subviews)
{
//handles ios6 and earlier
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
{
//we'll add a view to cover the default control as the image used has a transparent BG
UIView *backgroundCoverDefaultControl = [[UIView alloc] initWithFrame:CGRectMake(0,0, 64, 33)];
[backgroundCoverDefaultControl setBackgroundColor:[UIColor whiteColor]];//assuming your view has a white BG
[[subview.subviews objectAtIndex:0] addSubview:backgroundCoverDefaultControl];
UIImage *deleteImage = [UIImage imageNamed:delete_button_name];
UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,deleteImage.size.width, deleteImage.size.height)];
[deleteBtn setImage:[UIImage imageNamed:delete_button_name]];
[[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
}
//the rest handles ios7
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationButton"])
{
UIButton *deleteButton = (UIButton *)subview;
[deleteButton setImage:[UIImage imageNamed:delete_button_name] forState:UIControlStateNormal];
[deleteButton setTitle:@"" forState:UIControlStateNormal];
[deleteButton setBackgroundColor:[UIColor clearColor]];
for(UIView* view in subview.subviews){
if([view isKindOfClass:[UILabel class]]){
[view removeFromSuperview];
}
}
}
if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationView"])
{
for(UIView* innerSubView in subview.subviews){
if(![innerSubView isKindOfClass:[UIButton class]]){
[innerSubView removeFromSuperview];
}
}
}
if([subview.subviews count]>0){
[self recurseAndReplaceSubViewIfDeleteConfirmationControl:subview.subviews];
}
}
}
我希望这对某人有帮助。
关于ios - UITableViewCellDeleteConfirmationControl 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19159476/
我在项目中使用以下代码: if([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirma
这样使用 UITableViewCellDeleteConfirmationControl 可以吗: - (void)layoutSubviews { [super layoutSubview
目前我正在尝试自定义 UITableViewCell 中的删除按钮。现在我得到了类似的东西: 现在,我只需要更改此按钮的颜色即可,我不想更改其行为,也不想使其完全自定义。我确信这是可能的,无需创建您自
我是一名优秀的程序员,十分优秀!