Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton tag is nil

Tags:

ios

iphone

As far as I know the "tag" field in UIView is integer. Why one of my UIButtons has "nil" value in it's tag?

(lldb) po [button_one tag]
nil

I've set the tag 0 in designer, but still returns nil tag in code.

like image 859
AVEbrahimi Avatar asked Feb 08 '26 04:02

AVEbrahimi


2 Answers

po means 'print object'. An integer isn't an object. And nil would be equal to an integer value of zero.

So, in lldb you should be using p to print the integer value. And it is probably correct.

like image 101
Wain Avatar answered Feb 13 '26 17:02

Wain


My output is slightly different, but the point is, trying to print object on an integer (as Wain says) results in nil if the integer is 0 and an error if it is non-zero. (but in this case lldb still gives the p (int) value)

(lldb) po 0
$0 = 0 <nil>
(lldb) po nil
$1 = 0x00000000 <nil>
(lldb) po button.tag
$2 = 0 <nil>
(lldb) p (int)button.tag
(int) $3 = 0

Set the tag to 1

(lldb) po button.tag
$4 = 1 [no Objective-C description available]
(lldb) p (int)button.tag
(int) $5 = 1
like image 45
Matt Avatar answered Feb 13 '26 18:02

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!