“退出”为赛格瑞后与条件值的iOS /斯威夫特

问题描述:

这里是我的情况,“退出”为赛格瑞后与条件值的iOS /斯威夫特

我的应用程序,我用tablew观点得到后是显示的列表。上点击,它通过这个SEGUE带来一个postdetail观点:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    selectedIndexPath = indexPath.row 
    self.performSegue(withIdentifier: "push", sender: self) 
    self.feedTableView.reloadData() 
} 

随着火力地堡,我的一些帖子有一个条件published与布尔值(真/假)

我倒是想以某种方式,如果该值为false,禁用segue。由于有些帖子有“COMING SOON”标题,因此点击这些帖子时不会发生任何事情。

你知道这样做有什么可能吗?会很可爱!

非常感谢!

编辑 -

将被执行我的数据库,在那里你可以看到发布的条件enter image description here

+0

你为什么不使用的东西一样,如果(post.content.contains(! 'ComingSoon'){// performSegue}? –

+0

hm,这个想法是没有segue的工作,你怎么能'禁用'它?:) :) – tibewww

试试这个:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     guard posts[indexPath.row].title != "COMING SOON" else { 
      return 
     } 
     self.performSegue(withIdentifier: "push", sender: self) 
} 
+0

美丽!非常感谢它的魅力! – tibewww

+0

嗯,我刚刚注意到,它不适合其他职位的好数据!任何想法为什么:(? – tibewww

我不认为你可以“禁止”一个SEGUE,但你可以阻止它的结构在您的didSelectRowAtIndexPath委托方法中使用条件if语句。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    selectedIndexPath = indexPath.row 
    // get post info 
    let post = myArrayOfPosts[selectedIndexPath] 
    // check if post is COMING SOON 
    if post.title != "COMING SOON"{ 
     // if not, trigger the segue    
     self.performSegue(withIdentifier: "push", sender: self) 
    } 
    self.feedTableView.reloadData() 
} 

我会建议在一个恒定的“即将推出”的字符串值存储在你的班级,也可能在Enum,如果您有您想要一个不同的行为等称号。

编辑:我修复了我错误地写在第一位的if语句。我不能职位尚未置评(缺乏信誉的),所以希望你看到这个编辑:)