domesticcatsoftware / DCRoundSwitch

A 'modern' replica of UISwitch.
MIT License
765 stars 162 forks source link

Weird console output: snarfed from ivar layout: offText = OFF #5

Closed zebtin closed 13 years ago

zebtin commented 13 years ago

Everything works perfectly, events are fired correctly, and the control looks awsome.

But for some reason I get A LOT of these messages on the console:

....... ivar layout: offText = ON ivar layout: offText = OFF ivar layout: offText = ON ivar layout: offText = OFF ......

Has anyone found how to fix this or where it is coming from?

zebtin commented 13 years ago

Just to complement, now know this is related to Accessibility, but I still have not found a way to stop it from logging.

vpdn commented 13 years ago

I encountered the same issue when using the control in a UITableViewCell. The TableView automagically checks for accessibility features on each cell and seems to dump the warning when the accessibility methods are not implemented.

Stacktrace:

0 0x00028682 in -[DCRoundSwitch isAccessibilityElement] at ....

1 0x09f1f4c9 in AXAddAccessibilityElementsFromSubviews ()

0 0x00028682 in -[DCRoundSwitch isAccessibilityElement] at ....

1 0x09f14d36 in -[UITableViewCellAccessibility(SafeCategory) _accessibilityChildren]()

0 0x00028682 in -[DCRoundSwitch isAccessibilityElement] at ...

1 0x09f13cdb in -[UITableViewCellAccessibility(SafeCategory) _accessibilityHitTest:withEvent:]()

0 0x0002874e in -[DCRoundSwitch accessibilityTraits] at ..

1 0x09f29187 in -[UIAccessibilityElementMockView accessibilityTraits]()

Fix is quite simple, just implement the accessibility methods.

- (BOOL)isAccessibilityElement {
    return YES;
}    

- (NSString *)accessibilityLabel {
    return NSLocalizedString(@"On off switch", nil);
}

- (UIAccessibilityTraits)accessibilityTraits {
    return UIAccessibilityTraitButton;
}

- (NSString *)accessibilityHint {
    if (self.on) {
        return NSLocalizedString(@"Change switch to %@", self.offText);
    } else {
        return NSLocalizedString(@"Change switch to %@", self.onText);
    }
}
zebtin commented 13 years ago

Solved, thanks.