2017-02-16 25 views
0

這裏是我的情況,「退出」爲賽格瑞後與條件值的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

回答

0

試試這個:

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

0

我不認爲你可以「禁止」一個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語句。我不能職位尚未置評(缺乏信譽的),所以希望你看到這個編輯:)