Re: iOS: Cannot make debug messages disappear
Re: iOS: Cannot make debug messages disappear
- Subject: Re: iOS: Cannot make debug messages disappear
- From: Matthias Schmitt <email@hidden>
- Date: Tue, 12 Feb 2013 10:24:25 +0100
Hello,
On 12.02.2013, at 08:43, Chris Fleizach <email@hidden> wrote:
> I believe this is an issue in how custom table view cells are handled. If you used the standard mechanism for allow a delete button to appear on a swipe, I believe things would be handled correctly.
In fact, I could not use the standard method for creating the delete button. I have a set of table segments, each offering the possibility to enter account data with name (first row) and password (second row). When deleting account data, a complete table segment needs to be deleted. A user may swipe in the first or second row to make the delete button appear. For user interface consistency, the delete button should only appear in the first row.
I could not find any way to redirect the swipe in the second row to make the delete button appear in the first row using the standard mechanism. So I attached gesture recognizers to both rows, which make the delete button always appear in the first row like this
in my custom UITableViewCell class:
- (void)addGestureRecognizers {
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:controller action:@selector(cellSwipe:)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:rightSwipe];
[rightSwipe release];
… same for UISwipeGestureRecognizerDirectionLeft
}
So once the user swipes in the first or second row 'cellSwipe' is called. This method helps me to find the first row of the swiped segment and calls 'showDeleteButton'.
In my UITableViewController class:
- (void)cellSwipe:(UISwipeGestureRecognizer *)gesture
{
…
CGPoint location = [gesture locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
PrefUITableViewCell *firstCell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:indexPath.section]];
[firstCell showDeleteButton];
…
}
I mentioned the 'showDeleteButton' method before. Here a more complete version. I create the deleteButton and attach it as a subview. I make the subview appear using a small animation. Once the animation finishes, I am trying to inform VO that a layout change has happened using 'UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, deleteButton)'.
in my custom UITableViewCell class:
- (void)showDeleteButton
{
…
deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
…
[self.contentView addSubview:deleteButton];
[self.accessibleElements addObject:deleteButton];
deleteButton.frame = CGRectMake(buttonX, buttonY, 0.0, buttonHeight);
[UIView animateWithDuration:0.2
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
deleteButton.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
}
completion:^(BOOL finished) {
[deleteButton setIsAccessibilityElement:YES];
[deleteButton setAccessibilityElementsHidden:NO];
[deleteButton setAccessibilityTraits:UIAccessibilityTraitButton];
[deleteButton setAccessibilityLabel:@"Delete Account"];
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, deleteButton);
}];
}
The rest of my problem has been described in my previous mail. VO focuses the deleteButton once and cannot find it again, once the VO cursor moves away from it. So I implemented the UIAccessibilityContainer protocol to help VO finding the deleteButton. This works perfect, but makes the strange debug messages appear.
It's true, … with computers we solve problems, we never had without them. ;-)
Best regards
Matthias Schmitt
> On Feb 11, 2013, at 2:01 AM, Matthias Schmitt <email@hidden> wrote:
>
>> Hello,
>>
>> I am implementing a custom UITableViewCell for implementing a "swipe to delete" button. Once the user swipes the cell I am adding the delete button as a subview to the contentView of the cell. This is working fine for visual users, but once I am testing this in VoiceOver, VoiceOver misses the button as a subview. Using
>>
>> UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, deleteButton);
>>
>> the button is read once, but if I am moving the VO cursor back and forth, VO misses it again. So a visual disabled user cannot reach the delete button.
>>
>> To enable VO to always find the delete button in the cell, I am implementing the UIAccessibilityContainer protocol. Now VO always finds the delete button and everything is working fine for visual enabled and disabled users. My problem: I am getting debug messages like this:
>>
>> **** Accessibility: Could not find a valid index for <UITableViewCellContentView: 0x1e8fae10; frame = (10 1; 300 43); gestureRecognizers = <NSArray: 0x1e8fb000>; layer = <CALayer: 0x1e8fae70>> in -[PrefUITableViewCell indexOfAccessibilityElement:]
>> **** Accessibility: Could not find a valid index for <PrefUITableViewCell: 0x1e8fac80; baseClass = UITableViewCell; frame = (0 120; 320 45); autoresize = W; gestureRecognizers = <NSArray: 0x1d5fa2d0>; layer = <CALayer: 0x1e8fade0>> in -[UITableView indexOfAccessibilityElement:]
>>
>> Even though I have an array 'accessibleElements' filled with the elements, which should get accessible, iOS calls the 'indexOfAccessibilityElement' method other objects than those in the 'accessibleElements' array. Now my questions:
>>
>> - How can I make 'indexOfAccessibilityElement' be called only with those objects, which are in my 'accessibleElements' array?
>> - As everything is working right now, can I just ignore the debug message and continue? (I would prefer to not ignore these warnings, if possible.)
>>
>> Here some code, so you have a chance to give some advice:
>>
>> in my customised UITableViewCell:
>>
>> - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
>> {
>> …
>> accessibleElements = [[NSMutableArray alloc] init];
>> }
>>
>> - (void)dealloc {
>> [accessibleElements release];
>> …
>> }
>>
>> - (BOOL)isAccessibilityElement
>> {
>> return NO;
>> }
>>
>> - (NSInteger)accessibilityElementCount
>> {
>> return [self.accessibleElements count];
>> }
>>
>> - (id)accessibilityElementAtIndex:(NSInteger)index
>> {
>> return [self.accessibleElements objectAtIndex:index];
>> }
>>
>> - (NSInteger)indexOfAccessibilityElement:(id)element
>> {
>> return [[self accessibleElements] indexOfObject:element];
>> }
>>
>> - (void)showDeleteButton
>> {
>> …
>> deleteButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
>> …
>> [self.contentView addSubview:deleteButton];
>> [self.accessibleElements addObject:deleteButton];
>> …
>> }
>>
>> in my UITableViewController
>>
>> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
>> …
>> UILabel *txtLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10.0, 12.0, 130.0, 22.0)] autorelease];
>> …
>> [cell.contentView addSubview:txtLabel];
>> [cell.accessibleElements addObject:txtLabel];
>>
>> UITextField *txtBalanceName = [balanceNameTextFields objectAtIndex:indexPath.section];
>> …
>> [cell.contentView addSubview:txtBalanceName];
>> [cell.accessibleElements addObject:txtBalanceName];
>> …
>> return cell;
>> }
>>
>> This problem drives me crazy since three days. Please consider supporting my mental health. :-)
magic moving pixel s.a.
23, Avenue Grande-Duchesse Charlotte
L-3441 Dudelange
Luxembourg
Phone: +352 54 75 75 - 0
http://www.mmp.lu
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden