2011-10-25 30 views
0

我一直在讀一點我想弄清楚如何爲我的應用程序創建適當的視圖層次結構。我使用arc在xcode 4.2中創建了一個基本Tabbed應用程序,但是這個新應用程序不包含mainwindow.xib,所以很多使用IB的教程對我來說都是毫無用處的。我有一個5選項卡應用程序已經工作,應用程序的「基礎」按預期工作。我需要的是在當前正在查看的特定「標籤」窗口中包含更多視圖。我的思維很簡單,如下所示。我的猜測是有問號加入我只有5個基類,所有當前的tabBarControllerxcode 4.2選項卡式應用程序Heriarcy

應用heriarchy(建議)

Home (Currently UIViewController using homeViewController, convert to UINavigationController?) 
    Add (UIViewController with HomeAdd.xib?) 
    Edit (UIViewController with HomeEdit.xib 
    delete (UIViewController with HomeDelete.xib?) 

ViewList - Single page to view list (Currently UIViewController using viewListViewController) 

Share - Single page to send emails/invites (Currently UIViewController using shareViewController) 

Friends (UINavigationController with root view of FriendsRoot.xib?) 
    Add (UIViewController with FriendsAdd.xib?) 
    Edit (UIViewController with FriendsEdit.xib?) 
    delete (UIViewController with FriendsDelete.xib?) 

Settings - Single page for app settings/preferences (Currently UIViewController using settingsViewController) 

內UIViewControllers我甚至不知道,如果上述層次結構是可能的(即在tabBarController中混合視圖控制器),並且會喜歡關於如何以編程方式完成這個輸入,因爲這似乎是我在應用程序委託中的唯一選項,因爲默認情況下沒有mainwondiw.h/m/xib。爲此我的應用程序委託中

我當前的代碼如下:

AppDelegate.h

#import <UIKit/UIKit.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) UITabBarController *tabBarController; 

@end 

AppDelegate.m

@synthesize window = _window; 
@synthesize tabBarController = _tabBarController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    UIViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil]; 
    UIViewController *viewListViewController = [[ViewListViewController alloc] initWithNibName:@"ViewListViewController" bundle:nil]; 
    UIViewController *shareViewController = [[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil]; 
    UIViewController *friendsViewController = [[FriendsViewController alloc] initWithNibName:@"FriendsViewController" bundle:nil]; 
    UIViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil]; 
    self.tabBarController = [[UITabBarController alloc] init]; 
    [self.tabBarController setDelegate:self]; 
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController, viewListViewController, shareViewController, friendsViewController, settingsViewController, nil]; 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

我已經嘗試了一些嘗試注入UINavigationControllers ,或者使用自定義按鈕替代視圖,但所有這些都會導致構建失敗,因爲我仍在學習上下文和代碼。

任何建議將apprecaited。我以前的帖子迄今爲止取得了有限的成功。

謝謝

銀虎

回答

1

首頁(目前的UIViewController使用homeViewController,轉換爲UINavigationController的?) u可以使用UIViewController的產品

爲低於3 u可以使用模型視圖控制器或者你可以添加單獨的視圖。

添加(用的UIViewController HomeAdd.xib?) 編輯(用的UIViewController HomeEdit.xib 刪除(UIViewController中與HomeDelete.xib?)

的朋友也同樣情況下..

我不知道關於爲什麼沒有找到mainwindow.xib ..

+0

我同意..但每次我用XCode 4.2創建一個「標籤」應用程序時,它創建了應用程序委託文件,但沒有默認的xib ...我認爲這也很奇怪。我會嘗試和研究模態觀點,看看如何實現這些,如果你有任何非IB代碼我可以使用,我寧願在依賴IB之前學習它。 – Silvertiger

+0

另外,我可以使用我自己的按鈕來切換視圖(即家裏有3個自定義按鈕,會推...?模態視圖,如果我這樣做,它仍然會有標籤欄?看看我可以找到關於模態視圖的互聯網:) – Silvertiger

+0

好的..我發現一個頁面,解釋得很好(有一些調整)如何實現一個模態視圖,我已經得到它我工作的火焰...該頁面是「http://timneill.net/2010/09/modal-view-controller-example-part-1/」 - 只要我能做到這一點深層次,我很好: )...感謝您的指導。 – Silvertiger

0

壞消息是,由於新的Tab應用程序默認沒有「MainWindow.xib」,所以你不能在網上關注很多教程。好消息是,它仍然是非常容易實現的。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

方法您AppDelegate.m文件(其中你設置你需要實際添加型「的UINavigationController」的ViewControllers代替型「的UIViewController」你tabBarController的視圖控制器(您需要創建這些文件)。

例如(用於縮寫的緣故,我只表明我最後的UINavigationController聲明),

UINavigationController *nodes = [[NodeNavigationController alloc] initWithNibName:@"NodeNavigationController" bundle:nil]; 
self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:modems, nodes, home,viewController1, viewController2, nil]; 

最後,在你的UINavigationController的init方法(或類似)

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 

您需要添加此。 ..

Nodes *viewController = [[Nodes alloc] initWithNibName:@"Nodes" bundle:[NSBundle mainBundle]]; 
    self.viewControllers = [NSArray arrayWithObjects:viewController, nil]; 

現在在「節點」viewController中,您可以使用通常的「 [... pushViewController:...]「你一直使用的東西。

例如...

[self.navigationController pushViewController:viewController animated:YES]; 

我希望這是有幫助的。

相關問題