Bug 28674 - Xamarin.Mac 1.12 does not allow using NSFormatter for an NSTextField
Summary: Xamarin.Mac 1.12 does not allow using NSFormatter for an NSTextField
Status: RESOLVED ANSWERED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.12.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: 2.0.x
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2015-04-02 01:59 UTC by Curtis Wensley
Modified: 2015-04-02 13:29 UTC (History)
2 users (show)

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


Attachments
Duplicates the issue (18.57 KB, application/zip)
2015-04-02 01:59 UTC, Curtis Wensley
Details


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:
Status:
RESOLVED ANSWERED

Description Curtis Wensley 2015-04-02 01:59:11 UTC
Created attachment 10598 [details]
Duplicates the issue

I have implemented an NSFormatter based on the example here to limit the length of an NSTextField:

http://stackoverflow.com/questions/827014/how-to-limit-nstextfield-text-length-and-keep-it-always-upper-case

Using this in Xamarin.Mac 1.12 causes any text in the field to be lost completely.

This works fine in Xamarin.Mac 1.10.

To test, the example app attached should have text in both text boxes when started. In Xamarin.Mac 1.12, only the second text box has an initial value, and when you type in the first field then move focus to the second field, the text is lost.
Comment 1 Timothy Risi 2015-04-02 12:38:43 UTC
Hey Curtis,

I was able to get the text field to work with the formatter without blanking out when changing focus by changing:

public bool GetObjectValue(ref IntPtr obj, IntPtr value, ref IntPtr error)

to

public bool GetObjectValue(ref NSObject obj, NSString value, ref IntPtr error)

I also created a new bug (https://bugzilla.xamarin.com/show_bug.cgi?id=28696) to get the rest of the NSFormatter methods bound so they don't have to be manually exported.
Comment 2 Curtis Wensley 2015-04-02 13:00:57 UTC
Hi Timothy,

Ah, that's great!  I tried the same also, but used "ref NSString error" for the last parameter (which it should be I guess?), which causes a crash.

Thanks so much - this certainly will get me going for now.

Cheers!
Curtis.
Comment 3 Timothy Risi 2015-04-02 13:08:04 UTC
I just tried changing the error paramater to ref NSString and got a crash as well.  If you change it to "out NSString error" it works again (the "ref NSObject obj" also can be done as "out NSObject obj" if desired)
Comment 4 Curtis Wensley 2015-04-02 13:29:56 UTC
Aha, you are awesome!  I missed that detail of the api and totally makes sense why I was having problems.

Thanks again!