I have an annoying problem in my iOS app. Suddenly, when I start my view controller with a table view inside, I get the following error:
Unrecognized selector sent to instance
After googling a lot about this problem, it seems like it is usually related to a falsely connected IBOutlet/IBAction or generally something with the UI.
But I could exclude these causes, since I removed all IBOutlets and the problem still persisted.
After long hours, I found the solution for this and wanted to share it in a Q&A fashion, in case someone else is having a hard time on this.
The problem was this line of code:
outletCommentShowMore.attributedText = NSAttributedString(
string: isExpanded ? "show less" : "show more",
attributes: [
NSAttributedStringKey.foregroundColor : Theme.primaryTextColor,
NSAttributedStringKey.underlineStyle : NSUnderlineStyle.styleSingle
]
)
The error was that I passed an enum (NSUnderline.styleSingle) directly into the attributes dictionary of an NSAttributedString. But it has to be the rawValue of the enum!
So after changing this to NSUnderline.styleSingle.rawValue my error disappeared
Hope this helps someone
Related
I would liked to post a queued announcement
I tried using UIAccessibilitySpeechAttributeQueueAnnouncement but I have trouble converting it into an NSAttributedStringKey
Code:
let queueAnnouncementKey = NSAttributedStringKey(rawValue: UIAccessibilitySpeechAttributeQueueAnnouncement)
let announcementString = NSAttributedString(string: "something",
attributes: [queueAnnouncementKey : NSNumber(booleanLiteral: true)])
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, announcementString)
Problem:
The announcement is not queued, if there is an on going announcement at that moment, it ignores my announcement
Possible Cause:
I think something the way I create NSAttributedString is wrong
I think the NSAttributedString has changed from the time this presentation was made, so needed to use rawValue.
May be it is because it is not the correct raw value and that is causing it not to work.
Refer:
https://developer.apple.com/videos/play/wwdc2017-215/?time=1627
https://devstreaming-cdn.apple.com/videos/wwdc/2017/215avg3cuo2bu/215/215_whats_new_in_accessibility.pdf?dl=1
Don't worry, your code is correct with your annoucementString.
However, you should read this answer to understand the use cases why it doesn't work as you want because the system takes over when needs be and all the queued announcements are removed then.
Admittedly, I have a hard time with the wording of the Apple Docs so I might be missing something. However, it doesn't seem to be the case.
Here's the question.
Given:
let charSomeUUID = CBUUID(string: "12345678-1234-12234-1234-123456789qwe")
someCharacteristic = CBMutableCharacteristic(type: charSomeUUID, properties: [CBCharacteristicProperties.read, CBCharacteristicProperties.notify], value: nil, permissions: CBAttributePermissions.readable)
How would one provide an initial value for the value field?
I see how to do it in didReceiveRead. But I'd like to set an initial value.
I've tried putting a string into a data object and putting it in the value spot and that doesn't seem to work. And the swift 3 equivalent of the (Objective C) example in the Apple docs doesn't seem to work (anymore?).
Thanks for the help.
Apologies.
I actually had another piece of code that was wrong that ended up being the real problem.
For future reverence here is code to show that what I originally thought would not work does, in fact, work.
let stringValue : String = "something"
let dataValue = stringValue.data(using: String.Encoding.utf8)
// Device Info
someCharacteristic = CBMutableCharacteristic(type: someUUID, properties: CBCharacteristicProperties.read, value: dataValue, permissions: CBAttributePermissions.readable)
NOTE: When adding a value by this method your characteristic needs to be read only. Still some things to read up on there.
Failing to use read only results in the following error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Characteristics with cached values must be read-only'
Sulthan, thank you for your attention. Sorry for the mix up.
I'm trying to select an element of picker, the picker has Accessibility = picker_station, why can I do ? is something wrong ? or I need to use other code.
let app = XCUIApplication()
app.pickers["picker_station"].pickerWheels.element.adjust(toPickerWheelValue: "Aberdeen")
xcode error is:
Testing Failure - Internal error: unable to find current value '1 of 152' in possible values
Thanks
You are using it correctly, but the adjust(toPickerWheelValue:) method is buggy, as discussed here: https://forums.developer.apple.com/thread/16104
I agree with Oletha this seems to remain an unfixed bug in the framework.
We could fix the issue at least temporarily by calling
pickerWheel.swipeDown()
before calling
pickerWheel.adjust(toPickerWheelValue: "Value")
Otherwise we received the same crash.
After you displayed picker wheel on screen, you can update the value by:
app.pickerWheels.element.adjustToPickerWheelValue("Updated row value")
It's totally confusing on using this line
var docContents : NSArray! = NSFileManager.defaultManager().contentsOfDirectoryAtPath(archieveDirectoryPath,error:
&err)
I get the alert like SourceKit Service Terminated Editor Functionality temporary limited continuously, and gone swift coding style. But When I comment this line, all are disappeared.
Any one experienced this or is this a common error?
Note: I've tried this post's answer, But won't work. Just comment that line, it gets work. But I need that line. I'm using Xcode-6-beta-2
Finally fixed by below code. I think, it may common error. Just replace ! with ? symbol.
var docContents : NSArray? = NSFileManager.defaultManager().contentsOfDirectoryAtPath(archieveDirectoryPath,error:
&err)
But I didn't see any docs related how this happen. If anybody know, let me know. I think, this may temporary workaround.
I am trying to get the value "HELLO" of the UILabel shown in the iPad simulator.
I have enabled accessibility and have set the label as "Label Access".
But when I call target.logElementTree(), both the name and value are set to "LabelAccess" and as far as the apple docs say, the value field should contain the string that is set (in this case "Hello").
Does anybody know a fix for this?
PS: I am using the latest iOS SDK and Xcode.
Apple Stack Exchange
I think you encountered a UIAutomation bug that exists since forever.
Easiest way to get around this bug is to set the accessibilityValue to your text in code.
Something like this.
NSString *valueString = [NSString stringWithFormat:#"%d", value];
self.label.text = valueString;
self.label.accessibilityValue = valueString;
Helps those people that use Voice Over too ;-)
thanks for the workaround. Doesn't look like this bug has been fixed.
Came across this while writing Appium test for the iOS app. The element found by the driver somehow only contains accessibilityLabel and accessibilityIdentifier but not the actual text that's shown on the screen.
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value=<accessibilityLabel> name=<accessibilityIdentifier> label=<accessibilityLabel> .../>
Has someone found if this issue has been logged with apple?
EDIT: Refer to this answer and the comment underneath. https://stackoverflow.com/a/11411803/4725937
Basically need to use [accessibilityValue]: https://developer.apple.com/documentation/uikit/uiaccessibilityelement/1619583-accessibilityvalue for accessible components for the display text to show up as XCUIElementTypeStaticText.value in the page source.
For eg:
someUILabel.accessibiityLabel = "This is used for voice-over"
someUILabel.accessibilityValue = "This is displayed text"