プロジェクトで次のコードを使用しています。
if([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"])
これは iOS 5 および 6 では問題なく動作します。ただし、iOS 7 では常に NO が返されます。
これは iOS 7 の問題なのか、それとも私が何か間違っているのでしょうか。
ありがとう!
プロジェクトで次のコードを使用しています。
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];
}
}
}
これが誰かに役立つことを願っています。
その確認ボタンで何をしようとも、Apple が自由に変更できるテーブル ビュー セルの内部実装の詳細に依存しており、システムの更新後にソリューションが機能しなくなる可能性があります。あなたの場合、Apple はUITableViewCellDeleteConfirmationControl
もうテーブル セルでクラスを使用していないようです。
iOS 7 で機能をサポートしたい場合は、セルのサブビュー階層がそこでどのように変更されたかを確認する必要があります。これを行う可能な方法の 1 つは、-recursiveDescription
確認ボタンが表示されているときにセルにメソッドをログに記録することであり、次のような構造が表示されます (ログからいくつかの情報を削除しました)。
<MyCell: frame = (0 0; 320 44); >
| <UITableViewCellScrollView: frame = (0 0; 320 44);>
| | <UITableViewCellDeleteConfirmationView: frame = (320 0; 82 44);>
| | | <UITableViewCellDeleteConfirmationButton: frame = (0 0; 82 43.5);>
| | | | <UILabel: frame = (15 11; 52 22)>
| | <UITableViewCellContentView: frame = (0 0; 287 43.5);>
| | | <UILabel: frame = (15 0; 270 43.5)>
| | <_UITableViewCellSeparatorView: frame = (97 43.5; 305 0.5)>
| | <UIButton: frame = (297 16; 8 12.5)>
| | | <UIImageView: frame = (0 0; 8 12.5)>
ご覧のように、確認 UI を処理する 2 つのプライベート クラス - UITableViewCellDeleteConfirmationView と UITableViewCellDeleteConfirmationButton があるので、おそらくそれらを微調整する必要があります。
iOS 8 以降ではeditActionsForRowAtIndexPath
、メソッドを使用してボタンとアクションを定義できます。このリンクを参照してください