Swift:如何将视图控制器中的数据显示到详细信息视图控制器

时间:2016-09-30 09:28:01

标签: ios swift uitableview firebase firebase-realtime-database

我想将TableView中的特定数据显示给Details_View_Controller。

我有两个标签。一个标签是标题,我在详细信息(会议)_View_Controller中将其显示为标题。

但我有更多细节要在Details_V_C中显示。我从Firebase数据库检索的所有数据。在控制台中检索所有内容但是如何在Details_View_Controller中显示所有内容?

我读过这篇文章:https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewAndDataModel/TableViewAndDataModel.html#//apple_ref/doc/uid/TP40007451-CH5-SW2但我有一个SWIFT 3,本文并没有包含对最新版swift的正确解释。

JSON树:

"conferences": {

              "date": "some date"
              "deadline": "some deadline"
              "place": "some place"
              "title": "some title"

               }

查看控制器(TableView):

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("Cell")

        let messageSnapshot: FIRDataSnapshot! = conf[indexPath.row]
        let message = messageSnapshot.value as! Dictionary<String, String>

       // print(message)

        let label1 = cell?.viewWithTag(1) as! UILabel
        label1.text = message["title"]

        let label2 = cell?.viewWithTag(2) as! UILabel
        label2.text = message["place"]


        return cell!

    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {



        let messageSnapshot: FIRDataSnapshot! = conf[indexPath.row]
        let message = messageSnapshot.value as! Dictionary<String, String>

        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        let confDetails = storyBoard.instantiateViewControllerWithIdentifier("conferenceDetails") as! ConferenceViewController
        confDetails.title = message["title"]



        confDetails.conferenceDetailDict = message
        self.navigationController?.pushViewController(confDetails, animated: true)

    }

详情(会议)查看控制器:

class ConferenceViewController: UIViewController {

    var conferenceDetailDict: Dictionary<String, String> = Dictionary()

    override func viewDidLoad() {
        super.viewDidLoad()

        print(self.conferenceDetailDict)
        // Do any additional setup after loading the view.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

有人可以帮我解决这个问题吗?

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

一种方法是,如果你在TableView上保存plist,你想在Detail_V_C访问什么数据,并在加载Detail_V_C时得到

请参阅此链接:

How can i save, retrieve, delete & update my data in Plist file in ios?

@extends('layouts.header')
@section('content')
  <section class="content-header">
    <h1>
      Hello
    </h1>
  </section>
@stop  

当您加载Details_V_C访问plist并使用数据时,如果不再需要,则在解除confDetails_V_C时删除所有数据。

答案 1 :(得分:0)

到目前为止,我从您的问题中了解到,您无法从字典中检索所有数据

您可以通过以下方式访问字典的所有键和值

var keys = [String](conferenceDetailDict.keys)
var values = [String](conferenceDetailDict.values)

你可以像这样迭代字典

for (keys, values) in conferenceDetailDict {
    print("\(keys): \(values)")
}

在viewdidload中设置数据

相关问题