gpt4 book ai didi

ios - UITableViewCellDeleteConfirmationControl 问题

转载 作者:可可西里 更新时间:2023-11-01 04:04:47 25 4
gpt4 key购买 nike

我在项目中使用以下代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com