识别当前导航栏
我试图识别当前视图中的导航栏,以便我可以向其添加子视图。
我已经看到这段代码能够识别已动态创建和标记的导航栏:
UINavigationBar *theNavigationBar = (UINavigationBar *)[inParent.view viewWithTag:kNavigationBarTag];
但在我的情况下,导航栏不是动态创建的,因此它没有标记。还有其他方法可以识别吗?
I'm trying to identify the Navigation Bar in the current view so that I can add a subview to it.
I have seen this code which is able to identify the Navigation Bar that has been dynamically created and tagged:
UINavigationBar *theNavigationBar = (UINavigationBar *)[inParent.view viewWithTag:kNavigationBarTag];
But in my case the Navigation bar is not being created dynamically, so it's not tagged. Is there a way to identify it otherwise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,仅当从 UIViewController 中的方法调用时才有效。否则,尝试检索对视图控制器的引用并从那里获取它。
Only valid when called from a method in a UIViewController, of course. Otherwise, try to retrieve a reference to the view controller and take it from there.
如果您从
UIViewController
创建或访问UINavigationBar
,则可以为UINavigationBar
设置tag
属性 (self.navigationController.navigationBar
)因为
tag
是UIView
的属性,它是UINavigationBar
的超类,可能您正在引用下面博客文章中的代码.. .
http://iphonesdevsdk.blogspot.com/
You set the
tag
property forUINavigationBar
if you create or access it from yourUIViewController
(self.navigationController.navigationBar
)because
tag
is the property ofUIView
which is the super class forUINavigationBar
,May be you are referring code from the below blog post ...
http://iphonesdevsdk.blogspot.com/