为了做到这一点,我又回到了hello world教程。由于某种原因,我似乎无法弄清楚这一点,但它应该是如此简单。
我想要一个右边有按钮的UINavigationBar。当用户按下这个按钮时,它会通过侧滑动画将他们带到第二个视图,在这个新视图上,导航栏显示一个返回到前一个视图的按钮。
我怎样才能让这种情况发生呢?我无论如何也想不出来。有没有什么教程可以复习一下?我找不到。
发布于 2011-03-09 03:47:17
您应该创建一个以UIViewController为根的UINavigationController。在UIViewController中,您应该设置栏的右按钮。您应该有类似以下内容的内容:
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle: @"Next"
style:UIBarButtonItemStyleDone
target:self
action:@selector(nextPage:)]
autorelease];当您触摸按钮时,方法nextPage:将被调用,并将执行新视图的推送。
-(void)nextPage:(id)sender
{
UIViewController *secondViewController = [[UIViewController alloc] init];
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
}这是一个分为两部分的使用UINavigationController的教程,here是UINavigationController的官方文档(非常有用)。
发布于 2011-03-09 03:43:37
在按钮操作(选择器)上,在self.navigationController上使用以下消息
pushViewController:secondViewController animated:YES编辑:按如下方式创建UINavigationController:
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];然后按照索林在他的回答中提出的要求设置正确的按钮。并在self.navigationController上使用pushViewController:animated: message,正如我在原始答案中所发布的那样。希望能有所帮助。rootViewController是您希望作为导航堆栈上的第一个视图推送的视图控制器。
https://stackoverflow.com/questions/5237327
复制相似问题