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

因为,用户编辑问题,所以我再次给出答案。如果你想要带有 NavigationController 的 tabBar

在 AppDelegate.h 中定义生成UINavigationController *navController;属性并在 appDelegate.m 中进行综合。

在 AppDelegate.m 中导入所有 ViewController 类

喜欢

#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

更好的设置navController为:rootViewControllerwindow

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

viewController page1,当您添加到时,self.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

希望有帮助

于 2013-01-25T07:10:25.500 回答