2011-03-21 39 views
2

我是Objective-C的新手,我正在開發一個webradio應用程序。在應用程序中的任何位置的持久視圖

我的應用程序由TabBarController中包含的一些NavigationControllers組成。

我想做一個視圖,這將保持在TabBar所有的時間上方。 (它將包含音頻播放器控件,並且必須可在應用程序的任何位置訪問)

這樣做的最佳方式是什麼?

謝謝!

SQ,P

回答

2

您需要添加視圖作爲UITabBarController視圖屬性的子視圖:

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

這增加了的UILabel嗒嗒在爲所述的UITabBarController每個選項卡中的內容(m_tabBarController) 。

@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; 
+0

+1這是非常普遍的,特別是如果你希望廣告出現在整個應用程序。 AdWhirl建議這個確切的事情。 – 2011-03-21 20:18:48

+0

謝謝,我會嘗試。但是,實現UITabBarController的最好方法是什麼(在XCode模板中沒有.h&.m文件,tabBarController在appDelegate中聲明) – 2011-03-21 20:47:37

+0

您不需要實現UITabBarController。你只需要訪問在appDelegate中聲明的tabBarController(所以只需在你的appDelegate代碼中用self.tabBarController代替m_tabBarController)。 – RedBlueThing 2011-03-21 22:31:39

相關問題