Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableView[self.navigationController pushViewController:Page1动画:是];方法不起作用_Iphone_Uitableview_Pushviewcontroller_Addsubview - Fatal编程技术网

Iphone UITableView[self.navigationController pushViewController:Page1动画:是];方法不起作用

Iphone UITableView[self.navigationController pushViewController:Page1动画:是];方法不起作用,iphone,uitableview,pushviewcontroller,addsubview,Iphone,Uitableview,Pushviewcontroller,Addsubview,这是我的方法: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0 && indexPath.section == 0){ [self.navigationController pushViewController:Page1 animated:YES]; } if (indexPath

这是我的方法:

- (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方法都会发生这种情况) 我所要表达的观点只是一个普通的观点。 我可以添加所需的视图,但它们没有设置动画(因为我使用的是addSubview方法)


感谢您的帮助:)

我想您的导航控制器设置不正确,您可以在appdelegate.m文件中的didfishlaunchingwithoptions方法中实现这一点

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];

最好将
navController
设置为
窗口的
rootViewController

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;

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

在AppDelegate.h中定义
UINavigationController*navController并生成属性并在appDelegate.m中合成它

在AppDelegate.m中导入所有ViewController类


这可能会对您有所帮助。

当您将viewController页面1添加到
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

希望有帮助

您是否在UINavigationController中?self.navigationController=nil可能吗?我的方法说,在“AppDelegate”类型的对象上找不到属性“viewController”。我的应用程序是在xcode4.2.1中创建的,是一个基于选项卡的应用程序,如果这意味着什么的话,并将解释代码不起作用的原因。在这4行中,我收到了8个错误。tableview所在的控制器没有navigationcontroller作为父视图控制器。默认情况下,每个视图控制器的视图都有navigationController属性,但除非您已将导航控制器添加到窗口层次结构中,否则无法推送视图控制器。我的方法说,在“AppDelegate”类型的对象上找不到属性“viewController”。我的应用程序是在xcode4.2.1中创建的,是基于选项卡的应用程序,如果这意味着什么,并解释为什么代码不起作用。在这4行中,我收到了8个错误。
[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