开发者

viewWithTag and retrieving views deep within the hierarchy

开发者 https://www.devze.com 2022-12-30 00:16 出处:网络
if I have the following view hierarchy UIView --- top level view --UIButton --UIView ----UILabel ----UILabel -- tag = 1

if I have the following view hierarchy

UIView --- top level view

--UIButton

--UIView

----UILabel

----UILabel -- tag = 1

ho开发者_如何学Gow do I get UILabel with tag 1 from a reference from the top level view?


According to documentation, viewWithTag: returns “the view in the receiver’s hierarchy that matches tag.” This means it searches the whole hierarchy, not just immediate children. So, assuming that the UILabel you are looking for is the only view that has tag=1, you should be able to simply do

UILabel *someLabel = (UILabel *)[topLevelView viewWithTag:1];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号