0

私は自分のアプリに適切なビュー階層を作成する方法を理解しようと少し読んでいます。arcを使用してxcode4.2でベースのTabbedアプリケーションを作成しましたが、この新しいアプリにはmainwindow.xibが含まれていないため、IBを使用するチュートリアルの多くは私には役に立ちません。私はすでに5タブのアプリケーションを動作させており、アプリの「ベース」は期待どおりに動作しています。私が必要としているのは、現在表示されている特定の「タブ付き」ウィンドウ内により多くのビューを組み込むことです。私の階層は以下のように単純です。基本カテゴリが5つしかないため、推測に疑問符が追加されます。現在、すべてのUIViewControllerはtabBarController内にあります。

アプリの階層(提案)

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)

上記の階層が可能かどうか(つまり、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、またはカスタムボタンを使用した代替ビューを挿入する試みを数回試みましたが、コンテキストとコードをまだ学習しているため、すべて失敗したビルドになるようです。

どんなアドバイスも高く評価されます。これまでの投稿では、これまでのところ限られた成功しか収めていません。

ありがとうございました、

シルバータイガー

4

2 に答える 2

1

ホーム(現在、homeViewControllerを使用しているUIViewController、UINavigationControllerに変換しますか?)uはホームにuiviewcontrollerを使用できます

以下の場合、3 uはモデルビューコントローラーを使用するか、uは個別のビューを追加できます。

追加(UIViewController with HomeAdd.xib?)編集(UIViewController with HomeEdit.xib delete(UIViewController with HomeDelete.xib?)

友達も同じです。

mainwindow.xibが見つからなかった理由がわかりません。

于 2011-10-26T10:27:27.600 に答える
0

悪いニュースは、新しいTabアプリケーションにはデフォルトで「MainWindow.xib」がないため、オンラインで多くのチュートリアルをフォローできないことです。良いニュースは、それでも実装が非常に簡単なことです。

AppDelegate.mファイルの

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

メソッド(tabBarControllerのビューコントローラーを設定する場合、「UIViewController」タイプではなく「UINavigationController」タイプのViewControllerを実際に追加する必要があります(これらのファイルを作成する必要があります)。

たとえば(省略形のために、最後の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];

これがお役に立てば幸いです。

于 2011-11-15T21:00:24.460 に答える