Bug 3963 - ShouldReturn error
Summary: ShouldReturn error
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-03-19 06:09 UTC by Jonah
Modified: 2012-03-19 09:14 UTC (History)
3 users (show)

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

The attachment contains a comparable project with the problem. (1.32 MB, application/zip)
2012-03-19 06:09 UTC, Jonah

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 Jonah 2012-03-19 06:09:59 UTC
Created attachment 1535 [details]
The attachment contains a comparable project with the problem.


I have a problem with a UITextField delegate. The attachment contains a small project with the problem.
What I want to do is when you click the done button a UIAlertView will appear you have to fill in a barcode number and when you click the done button de UIAlertView must disappear.
When I click the done button monotouch is giving me an error. I can't find the solution for this problem. Can you help me?

Jonah Hulselmans
Comment 1 Jonah 2012-03-19 06:12:14 UTC
We have a similar piece of code in Objective-C and it works.
Comment 2 Sebastien Pouliot 2012-03-19 09:01:10 UTC
Are you using MonoTouch 5.0 (like the bug report says) or something more recent ?

Please add all product versions so we can use the same settings. You can find them in MonoDevelop (menu), About MonoDevelop (item), Version Info (tab) and copy-paste the data up to the assemblies versions.

Also if you could attach your objc sample it could help. Thanks
Comment 3 Jonah 2012-03-19 09:11:40 UTC
MonoDevelop info:

Installation UUID: 78f51f43-1acc-4c9e-af1e-c04e6c342d4f
	Mono 2.10.9 (tarball Wed Feb 29 17:12:24 EST 2012)
	GTK 2.24.10
	GTK# (
Mono for Android not installed
Apple Developer Tools:
	 Xcode 4.3.1 (1176)
	 Build 4E1019
Monotouch: 5.2.9 (Evaluation)
Build information:
	Release ID: 20808001
	Git revision: 68894cb4683cf4be662f84d8e786e75b47671d10
	Build date: 2012-02-28 22:59:41+0000
	Xamarin addins: 0aa7cf395748cfd1ff3d58df94b5cf38ed047c3e
Operating System:
	Mac OS X 10.7.3
	Darwin MacBook-Pro-van-Jonah-Hulselmans.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64

I will attach an Objective-C example.
Comment 4 Sebastien Pouliot 2012-03-19 09:14:44 UTC
Your issue is this line:

            UITextField input = barcodeEntry.GetTextField (0);

once the `openUIAlertView` method returns nothing (in the managed side) refers
to `input` so the GC can collect it (whenever it wants).

However you changed this `UITextField` instance (native side) by setting a
delegate to it. This means ObjectiveC (native side) will want to call back into
the delegate (and back into managed code) but it was collected -> crash.

The solution is to keep a reference to the instance so it won't be gargabe
collected (and will still exists/be valid when the native code call backs into
it). You can do this by promoting the local variable `input` as a type field.