从控制器移至上一个 [英] Moving back from a Controller to a previous one
问题描述
我正在尝试从UIViewController切换回UITableViewController,但是很遗憾,它无法按我想要的方式工作. 我确实从一开始就使用情节提要创建了我的界面,所以我并没有真正通过代码从一个View迁移到另一个View.到现在为止,我只是按序列推送了我的视图,这很容易通过情节提要实现.但是当我尝试移回以前的View时,将实现一个新的ViewController,因此我存储在旧视图中的所有数据都丢失了".
I'm trying to switch back from my UIViewController to my UITableViewController but apperendly it's not working the way I want it to. I did create my Interface with storyboards from the start, so I'm not really into moving from one View to another by code. Until now, I just pushed my Views per sergues which are easy to implement with storyboards. But when I tried moving back to my previous Views, a new ViewController will be implemented, so all my data I stored in the old one is "lost".
实际上(由于骚扰)我无法向您展示代码,但实际情况是:
Actually there is no code I could present you (because of the sergues) but the situation is:
->我有一个MutableArray在UITableView中存储内容.
->I got an MutableArray storing stuff in my UITableView.
->用户点击扫描"按钮,扫描应导入到我的阵列中的新项目.
->User taps the scan Button, scans a new Item which should be imported in my array.
->当试图返回到我的tableView时,有一个新的Controller令我不知所措,而没有意识到我存储在旧的Controller中的数据.
->When trying to push back to my tableView there's a new Controller awating me, unaware of the data I stored in the old one.
那我该如何简单地移回旧的Controller并阻止一直创建一个新的Controller?
So how do I simply move back to my old Controller preventing to create a new one all the time?
sergue-push总是创建一个新的Controller吗?
Does a sergue-push always creates a new Controller?
(问题可能很简单,但我是新手.尝试过搜索功能提供的一些结果,但没有一个起作用:()
(Question may be simple, but I'm new to this stuff. Tried some results presented by the search function, but none of them worked :( )
/edit:弹出问题已解决,但数组填充问题仍然存在.代码:
/edit: Popback problem has been solved but array filling problem still exists. Code:
GeneralSettings *sharedGS = [GeneralSettings sharedInstance];
sharedGS.strEAN = [[NSString alloc] initWithString:strCheckString];
[sharedGS.listArray insertObject:strCheckString atIndex:0];
NSLog(@"Anzahl der EAN-Codes: %d\nErster Code: %@\n In Variable: %@", sharedGS.listArray.count, [sharedGS.listArray objectAtIndex:0],sharedGS.strEAN);
sharedGS.strEAN中的数据(即"83274572354") listArray中的数据(空)
Data in sharedGS.strEAN ("83274572354" i.e.) Data in listArray (null)
推荐答案
您不要后退.这将创建先前控制器类的新实例.你弹出.您可以通过两种方法来实现.
You don't push back. That creates a new instance of the previous controller class. You pop back. You can accomplish that 2 ways.
1:要返回(弹出)平板电脑视图控制器时,请在下面的语句中输入代码.
1: In code put in the following statement when you want to return (pop) to you tablet view controller.
[self.navigationController popViewControllerAnimated:YES];
2:如果要在情节提要中执行此操作,则需要实现以下自定义segue类:
2: If you want to do it in storyboard you need to implement the following custom segue class:
实现
// PopSegue.m
#import "PopSegue.h"
@implementation PopSegue
- (void) perform {
UIViewController *src = (UIViewController *) self.sourceViewController;
[src.navigationController popViewControllerAnimated:YES];
}
和标题
// PopSegue.h
#import <UIKit/UIKit.h>
@interface PopSegue : UIStoryboardSegue
@end
将此方法放在UIViewController中,以将属性设置回UITableViewController:
Place this method in your UIViewController to set a property back to your UITableViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"goBackToTableView"]) {
[[segue destinationViewController] set{whatEverProperyYouWantTo}: {valueOfPropertyToSet}];
}
}
这篇关于从控制器移至上一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!