2016-12-01 75 views
3

我製作了自定義TableCell,並將Tableview添加到UIViewController。我想將數據從一個視圖(UITableViewController)發送到UIViewController,其中我已實施tableView。我收到此錯誤:發送數據時出錯

error

+0

請正確描述。我很困惑你在說什麼,並附上其他代碼。 –

+0

如上圖所示,我在將數據從一個視圖發送到另一個視圖時遇到特定錯誤。我想要發送的數據是NSArray數據類型。 – Ronit

回答

0

在你Storyboard你Segue公司連接,因爲你得到發件人爲UITableViewCellUITableViewCellViewController之間。要解決這個問題,只需刪除該Segue並創建一個從源ViewController到目的地ViewController並設置相同的segue標識符後,一切都將以您想要的方式工作。

+0

我正在從UITableViewController發送數據到UIViewController Named BookingHistoryViewController。 BookingHistoryViewController是UIView的類,其中我添加了表視圖使CustomCells和CustomCell我已經使用BookingHistoryTableViewCell,你可以看到,在方法prepareForSegue – Ronit

+0

@Ronit我在說的是,在故事板你的segue連接beteween tableCell和ViewController,而不是你需要在兩個ViewController之間創建的。 –

+0

感謝您的幫助 – Ronit

0

您的問題尚不清楚。雖然我給你想法。 您必須使用關閉,委託或通知模式

假設我從view1 to view2發送消息。使用簡單的過程發送數據。但是,如果從view2發送到VIEW1 - >在封閉view2: - >定義的蓋,

var sendDataToBackController: ((String)->())? 

@IBAction func DataSendFrom2ndVCTo1stVC(_ sender: AnyObject) { 
      if let handler = sendDataToBackController{ 
       handler("Message From ViewController3 to ViewController2") 
       } 


      _ = self.navigationController?.popViewController(animated: true) 
     } 
    } 

view1: - >

if let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewController2") as? ViewController2{ 
       vc.dataFrom1StVC = "message send from 1st VC" 
        vc.sendDataToBackController = { 
       message in 
       print(message) 
       }     
       self.navigationController?.pushViewController(vc, animated: true) 
      } 
     } 

請撥打封口即將上面的過程,即將數據從view2傳回view1,並在上面儘快創建view2實例。我只給出主意。如果你想獲得詳細的代碼,那麼請給你詳細的問題。 希望它能幫助你。

+0

非常感謝您的幫助,您可以告訴我如何添加代碼,因爲stackOverFlow不會輸入太多字符 – Ronit

+0

您可以像在stackOverFlow中一樣添加代碼。如果您想標記上面寫的代碼,首先將代碼寫入答案框,就像您寫的那樣,然後選擇您想要標記的代碼並按(控制+ K)鍵。如果我的回答對你有幫助,那麼請檢查我的答案,並注意。如果有任何困惑,然後問我。謝謝 –