我对segues感到很困惑。有许多不同的方法来更改当前的ViewController,我不知道使用哪种方法并将它们混合起来。
我目前拥有的是一个MainViewController。在这上面我有4个按钮。第一个按钮与Show(例如Push)Segue连接。在Segue的另一边是带有View Controller的导航控制器。现在,这不需要额外的代码。
现在是我的第一个问题。导航控制器永远不会显示,对吧?仅显示视图控制器。但是如果我想在右侧添加一个导航项按钮以返回到第一个View Controller我该怎么办?我需要像这样添加程序化按钮:
public static Object clone(Serializable object) {
return deserialize(serialize(object));
}
这是对的吗?
现在下一步是,我需要打开另一个视图来编辑事件的详细信息,这些事件在上一个视图中显示为表格。当我单击表格行时,编辑视图应该打开,我需要传递事件对象。我如何用segues做到这一点? 完成编辑后,如何在编辑视图中添加程序化取消和保存按钮,还是返回所有事件概述吗?
答案 0 :(得分:2)
您的编码很好,并添加以下行
UIBarButtonItem *leftBackToPreviousScreenButton = [[UIBarButtonItem alloc]
initWithTitle:@""
style:UIBarButtonItemStylePlain
target:self
action:@selector(back)];
// add this line
self.navigationItem.rightBarButtonItem = leftBackToPreviousScreenButton;
- (void)back
{
// if you want to pop on previous view controller
[self.navigationController popViewControllerAnimated:YES];
}
在上一个问题中您需要自定义,但如果您需要在两个视图控制器之间传递数据,请使用此link
答案 1 :(得分:1)
请勿忘记实施UINavigationController
并将UIViewController
分配为4个按钮root view controller
。显示segues会显示导航栏,但其他人不会,在这种情况下,您需要管理它并添加它。
要显示详细信息,只需覆盖方法prepareForSegue:sender
即可:
[self performSegueWithIdentifier:@"NextSegue" sender:nil];
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"NextSegue"]) {
NextViewController *nextViewController = (NextViewController*)[segue destinationViewController];
nextViewController.details = self.details;
// nextViewController.details is the property "details" declared in your NextViewController.h file, you just give it the value you want to send from your present one.
}
}