0

我有一个应用程序,它有一个 UITabBarController 作为 rootviewcontroller。UITabBarController 有四个项目。四个 UIViewConotroller 嵌入在 UINavigationControllers 中。我可以在 UINavigationController 上添加按钮或图像。但是,对于同一个按钮或图像,我必须在每个 UINavigationController 上重复 4 次。是否可以在设置为 rootviewcontroller 的 UITabBarController 顶部添加按钮或图像?提前致谢。

4

1 回答 1

0

从理论上讲,您可以通过以下方式做到这一点:

UIButton *button = ; // your button
button.frame = CGRect(...); // position on the screen, where you want to have the button

[rootViewController addSubview:button];

但是,强烈不建议使用此解决方案。

相反,您可以做的是创建一个抽象类MyViewControllerWithButton : UIViewController,该类将实现viewDidAppear:创建UIButton并将其添加到导航栏。

您在标签栏中使用的所有视图控制器都将是 MyViewControllerWithButton 的子类。

于 2013-10-24T19:14:07.933 回答