2016-02-09 78 views
2

我試圖通過segue將值從領域傳遞給另一個viewcontroller。問題在於它發生錯誤:Reciever沒有標識符。我嘗試了另一種方式,準備好了,但它的效果不如這個。接收器沒有標識符swift 2

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    let lektire = datasource[indexPath.row] 
    let destinationVC = DetaljiViewController() 
    destinationVC.programVar = lektire.ime 
    destinationVC.performSegueWithIdentifier("oLektiri", sender: self) 
} 

但是,我的segue肯定存在,其標識符已正確設置(請參閱下面的屏幕截圖)。

Here is the screenshot of segue

這是怎麼回事,我怎麼能解決這個問題?

+0

對不起,我錯過了您在故事板中的其他細節! – dasblinkenlight

回答

0

我相信這是你正在尋找的,你必須從你目前所在的視圖控制器中調用performSegueWithIdentifier,或者讓發送者成爲indexPath,或者你可以將它變成你的數據源項目。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    self.performSegueWithIdentifier("oLektiri", sender: indexPath) 

    // Another WAY 
    self.performSegueWithIdentifier("oLektiri", sender: datasource[indexPath.row]) 
} 

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if(segue.identifier == "oLektiri") { 
     let indexPath = sender as! NSIndexPath 
     let toViewController = segue.destinationViewController as? NextViewController 
     let lektire = datasource[indexPath.row] 
     toViewController?.selectedObject = lektire 
    } 

    // Another WAY 
    if(segue.identifier == "oLektiri") { 
     let lektire = sender as? lektireTYPE 
     let toViewController = segue.destinationViewController as? NextViewController 
     toViewController?.selectedObject = lektire 
    } 
} 

// An example of what the next view controller should look like 
class NextViewController: UIViewController { 
    var selectedObject: ObjectType? 
} 
+0

它給出了錯誤 - >不能指定'PrikaziLektire'類型的值來鍵入字符串?它給了我這個錯誤,我試圖解決這個問題 – Filip

+0

我可以看到代碼可能這是一個類型不匹配的意思,你試圖設置一個變量是一個字符串?到一個對象是PrikaziLektire這是不可能的 –

+0

第一視圖控制器http://paste.ofcode.org/ZCChbc4ydTsSLRTHGhedp2 秒http://paste.ofcode.org/sCTFrkFBxjFWgCaRqm8sC5 – Filip

相關問題