【问题标题】:Unable to push the VIEW无法推送 VIEW
【发布时间】:2011-11-03 10:31:42
【问题描述】:

我有一个仪表板视图,上面绘制了标签和图像视图。 在我的应用程序中,当我触摸任何 ImageView 时,我想推送位于 StaticPage.h 中的视图。

我使用了 UITouch 的概念,它的方法“- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event”如下:

 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"touches began");

if ( [touch view] == _icon) {
StaticPage *staticPage = [[StaticPage alloc] initWithNibName:@"StaticPage" bundle:nil];
[self.navigationController pushViewController:staticPage animated:YES];
[staticPage release];
}

}

从 UIViewController 继承的 StaticPage。 _icon 是一个 UIImageView。

在AppDelegate中,这个方法“- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions”如下:

  self.window.rootViewController = self.viewController;
[_window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;

其中 navController 在 StaticPage 的 .h 文件中声明为 UINavigationController *navController;并合成到StaticPage的.m文件中。

我想知道为什么我的来自 StaticPage 的视图没有被推送? 任何帮助...在此先感谢您

【问题讨论】:

  • navController 不应在 StaticPage 的 .h 中声明。它应该在你的主视图控制器中声明。
  • 感谢您的评论。我应该在要推送视图的类方法中声明 navController 吗?

标签: objective-c xcode uinavigationcontroller uitouch


【解决方案1】:

我找到了导航但没有使用方法 pushViewController:animated。 使用 presentModalViewController:animated 我们可以导航到所需的页面。

【讨论】:

    猜你喜欢
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 2016-12-14
    • 2019-05-04
    • 2018-02-27
    相关资源
    最近更新 更多