开发者

obtaining UINavigationController in an UIView

开发者 https://www.devze.com 2023-04-07 18:17 出处:网络
a custom tab bar controller I am using applies the ViewController or UINavigationController like this:UIViewController* viewController = [data objectForKey:@\"viewController\"];

a custom tab bar controller I am using applies the ViewController or UINavigationController like this: UIViewController* viewController = [data objectForKey:@"viewController"];

I dont knw exactly how it works but "viewController" comes out as a UINavigationController. Next, the custom tab bar controller class adds a tag like so, viewController.view.tag = THE_TAG;

Retrieving the controller is uses UIView* currentView = [self.window viewWithTag:SELECTED_VIEW_CONTROLLER_TAG];

This part is where I get confused because now when I nslog this "currentView" I get a UILayout etc... instead of my UINavigationController. I'm assuming it applied the tag to the UIView that contained the nav controller?

How do I reference the UINavigationContr开发者_StackOverflow中文版oller within this UIView?


In the above what is THE_TAG, and can you confirm that it is unique (i.e. not zero, and not matching something being used elsewhere by the same mechanism)?

I'd be pretty wary overusing tag since there is no easy way to gaurentee globally unique tags, and when using something like self.window viewWithTag you could see just about every view in the app being checked.


It seems like you have a view and a viewController confused. A UINavigationController is a subclass of UIViewController. It is not a subclass of UIView. UIViewControllers do have a property which is a UIView class. It is probably this property that you are accessing when you use viewWithTag: . So maybe, when you use that method, you are not accessing the UINavigationController but the UINavigationController's view property (which is actually something you should probably not be messing with.)

0

精彩评论

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

关注公众号