【问题标题】:Persistant view anywhere in the app应用中任何位置的持久视图
【发布时间】:2011-03-21 18:42:13
【问题描述】:

我是 Objective-C 的新手,我正在开发一个网络广播应用程序。

我的应用由 TabBarController 中包含的一些 NavigationController 组成。

我想制作一个始终保持在 TabBar 上方的视图。 (它将包含音频播放器控件,并且必须可以在应用程序的任何位置访问)

最好的方法是什么?

谢谢!

SQ;p

【问题讨论】:

    标签: iphone ios view uiviewcontroller uitabbarcontroller


    【解决方案1】:

    您需要将视图添加为UITabBarController 视图属性的子视图:

    m_yourToolbar =[[UIToolbar alloc] initWithFrame:CGRectMake(0, 401, 320, 44)];
    // set some properties on the toolbar
    // ...
    [self.tabBarController.view m_yourToolbar];
    

    这会在 UITabBarController (m_tabBarController) 中的每个选项卡的内容上添加 UILabel blah。

    @interface YouAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
        UIToolbar * m_yourToolbar;
    
        // ... whatever other stuff you have in your app delegate
    }
    
    @property (nonatomic, retain) UIToolbar * yourToolbar;
    

    在您的应用委托实现中,您将需要:

    @synthesize yourToolbar= m_yourToolbar;
    // .. other app delegate stuff
    

    因此,在需要更新工具栏的视图控制器中,您可以获取应用委托,获取 yourToolbar 属性并在其上设置属性:

    AppDelegate *appDelegate = (YouAppDelegate *)[[UIApplication sharedApplication] delegate];
    // set stuff on the toolbar property
    appDelegate.yourToolbar.stuff = stuff;
    

    【讨论】:

    • +1 这很常见,尤其是当您希望广告出现在整个应用程序中时。 AdWhirl 提出了这个确切的建议。
    • 谢谢,我会试试的。但是实现 UITabBarController 的最佳方法是什么(在 XCode 模板中没有 .h 和 .m 文件。tabBarController 在 appDelegate 中声明)
    • 你不需要实现UITabBarController。您只需要访问 appDelegate 中声明的 tabBarController(因此只需在 appDelegate 代码中将 m_tabBarController 替换为 self.tabBarController)。
    • 我怎样才能从应用程序的任何地方修改 blah 标签? (例如来自 navigationController.view 的子视图)
    • @SQuat 哦,明白了。您只需要使 UILabel * blah 成为您的应用程序委托的成员(和属性)。这样你就可以获取应用程序委托,然后从任何你喜欢的地方设置 blah 属性上的文本。 :)
    猜你喜欢
    • 1970-01-01
    • 2018-05-17
    • 2018-10-30
    • 2019-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    相关资源
    最近更新 更多