Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Ios 如何防止执行同一个序列两次?_Ios_Objective C_Segue_Uistoryboard_Uistoryboardsegue - Fatal编程技术网

Ios 如何防止执行同一个序列两次?

Ios 如何防止执行同一个序列两次?,ios,objective-c,segue,uistoryboard,uistoryboardsegue,Ios,Objective C,Segue,Uistoryboard,Uistoryboardsegue,我的iOS应用程序中的导航有问题。我有带菜单项表视图的滑动菜单。点击其中一个项目将触发segue,从而在堆栈上推送新的视图控制器。问题是我可以在同一个堆栈上推同一个视图控制器两次。若我选择菜单项“A”,那个么相应的视图控制器被推到导航堆栈上。从这个新推出的视图控制器中,我还可以选择相同的“A”菜单项,并推出与最顶层视图控制器相同类别的新距离。我怎样才能防止呢 无效解决方案: 正在检查导航堆栈顶部控制器的类。但问题是,我只知道segue的标识符(NSString*对象),无法获得有关目标视图控制器

我的iOS应用程序中的导航有问题。我有带菜单项表视图的滑动菜单。点击其中一个项目将触发segue,从而在堆栈上推送新的视图控制器。问题是我可以在同一个堆栈上推同一个视图控制器两次。若我选择菜单项“A”,那个么相应的视图控制器被推到导航堆栈上。从这个新推出的视图控制器中,我还可以选择相同的“A”菜单项,并推出与最顶层视图控制器相同类别的新距离。我怎样才能防止呢

无效解决方案:
正在检查导航堆栈顶部控制器的类。但问题是,我只知道segue的标识符(NSString*对象),无法获得有关目标视图控制器类的信息。我唯一可以检查该类的地方是方法:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
但是我不能阻止从这个方法执行segue


我已尝试在属性中保存上次执行的segue,但它无法工作,因为当我按“A”视图控制器,然后按“B”视图控制器,然后按“后退”按钮时,我将无法再次按B,这是错误的:)

您需要以下方法

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender 
只需返回false即可取消该序列。您将有如下内容(伪代码):


我也有同样的问题,现在已经解决了。请让我知道这是否有帮助

我已经有一个从表视图单元格链接到另一个名为DynamicSuperView的视图的segue

func tableView(_tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{
//Remove the below line from this function as it will perform segue.
//performSegue(withIdentifier: "DynamicSegue", sender: self)
}


override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?)         {
// This will actually perform your segue
var DestViewController = segue.destination as! DynamicSuperView 
let selectedRow = tableView.indexPathForSelectedRow?.row
DestViewController.labelText = names[selectedRow!]
}

我通过检查堆栈中的ViewControllers数组来管理类似的内容<代码>self.navigationController.viewControllers是的,我知道这个方法。但这里面有什么逻辑。正如我在问题中所写的那样,我无法获取要执行的segue目标视图控制器的类。您可以为所有视图控制器创建父类,并在其中保存所有执行的segue标识符。然后,您应该检查活动segue是否在已执行列表中,然后它应该被取消,但是“shouldPerformSegueWithIdentifier”方法不会经常调用,因此我们必须添加一些条件<代码>如果([self-shouldPerformSegueWithIdentifier:@”“sender:nil]){[self-performSegueWithIdentifier:@”“sender:self];}什么意思,每次使用segue时都会调用shouldPerformSegueWithIdentifier
func tableView(_tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{
//Remove the below line from this function as it will perform segue.
//performSegue(withIdentifier: "DynamicSegue", sender: self)
}


override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?)         {
// This will actually perform your segue
var DestViewController = segue.destination as! DynamicSuperView 
let selectedRow = tableView.indexPathForSelectedRow?.row
DestViewController.labelText = names[selectedRow!]
}