0

ここに私の方法があります:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath    *)indexPath
{
if (indexPath.row == 0 && indexPath.section == 0){
    [self.navigationController pushViewController:Page1 animated:YES];
}
if (indexPath.row == 1 && indexPath.section == 0){
    [self.view addSubview:Page2.view];  
}

さて、私は方法をから変更しました

[self.view addSubview:Page1.view]; //this works perfectly however as soon as I change to this
[self.navigationController pushViewController:Page1 animated:YES];// this does not work

メソッドが呼び出されています。NSLog の前後を追加し、両方が呼び出されました。ただし、このメソッドを呼び出すと、セルが青色に変わるだけです (ただし、これは addSubview メソッドと pushViewController メソッドの両方で発生します)。プッシュ先のビューは通常の UIView です。必要なビューを追加できますが、アニメーション化されていません (addSubview メソッドを使用しているため)

ご協力いただきありがとうございます :)

4

4 に答える 4

1

ナビゲーションコントローラーに適切に設定していないと思いますが、appdelegate.m ファイルの didFinishLaunchingWithOptions メソッドでこれを実装できます。

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];

[self.navController.navigationBar setBarStyle:UIBarStyleBlack];

[self.window addSubview:self.navController.view];
于 2012-10-26T10:01:16.177 に答える
0

navController現時点でrootViewControllerより良いセットwindow

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.navController.navigationBar setBarStyle:UIBarStyleBlack];

self.window.rootViewController = self.navController;
于 2012-10-26T10:10:51.657 に答える
0

、ユーザーが質問を編集したため、もう一度回答しています。NavigationController で tabBar が必要な場合

IN AppDelegate.h appDelegate.mUINavigationController *navController;でプロパティを定義して作成し、合成します。

すべての ViewController クラスを AppDelegate.m にインポートします

お気に入り

#import "ViewController.h"
#import "Preview.h"
#import "Export.h"
#import "Settings.h"
#import "More.h"



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.


tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;

//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
ViewController * search = [[ViewController alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc]        initWithRootViewController:search];

Preview* nearby = [[Preview alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];

Export* map = [[Export alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];

Settings* aboutUs = [[Settings alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];

More* favorites = [[More alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];

NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];

tabBarController.viewControllers = controllers;

[self.window addSubview:tabBarController.view];

//  self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
//  self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;

}

これはあなたを助けるかもしれません。

于 2012-10-26T12:32:34.917 に答える
0

に追加したときのviewControllerページself.view 1は、すでにビューの一番上にあるため、プッシュしているときにどのようにアニメーション化できますか

[self.view addSubview:Page1.view]; //this works perfectly however as soon as I change to this
[self.navigationController pushViewController:Page1 animated:YES];// this does not work

それが役立つことを願っています

于 2013-01-25T07:10:25.500 に答える