is "zero" a reserved tag number in cocoa?
I want to know if zero is a reserved tag number in cocoa.
I ask because I was building UIButtons in a for loop fro开发者_StackOverflowm 0 - n and assinging the loop index as each created buttons tag.
Then when I tried to reference using viewWithTag and tried to change a property I get a sigbart error for the button with tag zero. All of the other buttons work fine.
To get my code to work I've had to create the buttons using for 1 - n+1
tag
is an integer instance variable in UIView subclasses and as any other integer ivar it is initialized with 0 by default.
So in your case any subview tag that was not set explicitly to some value will be equal to 0 and if there are several such subviews viewWithTag:
method may return any of them - probably it just returns not an UIButton instance and you access some button-specific properties in your code so getting exception (unrecognized selector sent?) in run-time.
According to the documentation, the default value for a tag is zero. (i.e.: UIViews, etc. with no specific tag value set will be zero.) As such, it's likely that the SIGBART is being caused by the fact that you're attempting to reference multiple (or simply an invalid) control when you call viewWithTag with a zero value.
In order words, you should really start custom tag numbering at 1.
精彩评论