Bug 19722 - -[UITextView positionWithinRange:atCharacterOffset:]: unrecognized selector sent to instance
Summary: -[UITextView positionWithinRange:atCharacterOffset:]: unrecognized selector s...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 6.3.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-05-13 08:58 UTC by John Hair
Modified: 2014-05-13 09:19 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description John Hair 2014-05-13 08:58:54 UTC
Uunrecognized selector issue. Example code below, entry is a UITextView:
entry.GetPosition(entry.SelectedTextRange, 0);

Version: (Business Edition)
Comment 1 Sebastien Pouliot 2014-05-13 09:19:47 UTC
That can happen (it's not a bug). `GetPosition` calls the `positionWithinRange:atCharacterOffset:` selector.

This selector is defined in an ObjC protocol: `UITextInput` [1]. `UITextView` [2] conforms to the `UITextInput` protocol. 

However, unlike C# interfaces, some protocol members can be optional. IOW `UITextInput` does not have to implement everything from `UITextInput`. 

If it does not implement it (and you call it) then you'll get a "unrecognized selector sent to instance" message. This is a reason why you'll often see ObjC code that calls `respondToSelector` before calling some code. You can do the same (check) in your code.

Note: Newer version of XI handle protocols differently but, for backward compatibility, you'll still find some "protocol" members inside types (like UITextView). It makes it clearer that the method comes from a protocol (but it does not change what the native ObjC type implements).

[1] https://developer.apple.com/library/ios/documentation/uikit/reference/uitextinput_protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITextInput/positionWithinRange:atCharacterOffset:

[2] https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextView_Class/Reference/UITextView.html