Bug 12557 - Tag not accepting a value of 0
Summary: Tag not accepting a value of 0
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.3.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-06-05 08:05 UTC by Paul Johnson
Modified: 2013-06-05 09:44 UTC (History)
2 users (show)

Tags:
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:
Status:
RESOLVED FEATURE

Description Paul Johnson 2013-06-05 08:05:35 UTC
I have created a number of buttons on the fly and so I know what has to happen with them in the button handler event, I've attached a tag to them using this

int number = new int();
number = counter;
btn.Tag = number;

If the number if zero, btn.Tag is not set at all. All other numbers work.
Comment 1 Sebastien Pouliot 2013-06-05 08:20:03 UTC
Not sure what you mean, the following works for me:


		[Test]
		public void Tag_12557 ()
		{
			using (UIButton b = new UIButton ()) {
				Assert.That (b.Tag, Is.EqualTo (0), "default");
				b.Tag = Int32.MaxValue;
				Assert.That (b.Tag, Is.EqualTo (Int32.MaxValue), "Int32.MaxValue");
				b.Tag = Int32.MinValue;
				Assert.That (b.Tag, Is.EqualTo (Int32.MinValue), "Int32.MinValue");
				b.Tag = 0;
				Assert.That (b.Tag, Is.EqualTo (0), "0");
			}
		}


Can you attach a self-contained test case ? along with extra informations about the version of the products and iOS (sim or devices) that you're using.

The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 2 Paul Johnson 2013-06-05 09:27:03 UTC
Sure - I'm using the latest alpha code - 6.3.6.76, iOS 6.1.3 - only tested on the simulator

The code I'm using is this

float[] xpos = new float[] { 10f, 114f, 216f };
int n = 0, counter = 0;
UIView row = new UIView(new RectangleF(0f, 52f, AppDelegate.Self.ScreenX, 114f));
            for (int i = 0; i < chemicals.Count; ++i)
            {
                if (n == 3)
                    n = 0;

                UIButton myButton = new UIButton(new RectangleF(xpos[n], 10f, 94f, 94f));
                UIUtils.ButtonWithImage(myButton, "Graphics/temp/chemicals.png", chemicals[counter], new RectangleF(12f, 4f, 70f, 70f),
                                        new RectangleF(4f, 78f, 86f, 12f), true, true);

                int tag = new int();
                tag = counter;
                myButton.Tag = tag;
                myButton.TouchUpInside += ChemicalButtonPressed;
                chemicalButtons.Add(myButton);
                n++;
                counter++;
            }

UIUtils.ButtonWithImage sticks an image onto the button with some text

In the debugger, only those with Tag != 0 show as having a tag number.
Comment 3 Sebastien Pouliot 2013-06-05 09:44:27 UTC
Ok, I see what you mean. From [1] you can see that 0 is the default value:

> The default value is 0. You can set the value of this tag and use that value to identify the view later.

What the debugger shows, by default, for any instance is what the `ToString()` method returns.

By default, all `NSObject` returns the `description` (selector). IOW `myButton.ToString ()  == myButton.Description`.

For UIButton the `description` selector returns a string like:

   <UIButton: 0x176b41b0; frame = (0 0; 0 0); opaque = NO; tag = 2147483647; layer = <CALayer: 0x17615ce0>>

but `tag` is not included when it's the default value (0). That's by (Apple) design, some properties are always shown (e.g. frame), some are shown only when not the default (e.g. tag) and some are never shown at all.

However that does not mean the Tag value (and C# property) is not set. If you access `myButton.Tag` from your event handler then it will have the correct (0 or otherwise) value.

[1] http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html