Master-DetailView应用程序

时间:2016-11-21 00:45:51

标签: ios iphone swift uitableview master-detail

我正在尝试创建一个Master详细信息View Application&我有点卡住了。

我有一个带有100 DynamicPrototype Cells的tableView,显示条形码,当我点击cell时,我想提供有关该条的更多信息。

我的问题是如何将不同的data labelsimages填入DetailView并更改每个cell我点按以表示正确data

我的DetailviewTableViewController StaticCells,如下所示:

Bars My Friends

我正在使用Swift 2.3和Xcode 8.1

我创建了一个代表我的DetailView数据的类:

BarProfile.Swift:

import Foundation

class BarProfile {
    var HeaderImage = ""
    var HeaderTitle = ""
    var Age = ""
    var Adress = ""
    var Number = ""
    var Time = ""
    var Music = ""
    var Info = ""
    var Menu = ""
    var More = ""

    init(HeaderImage: String, HeaderTitle: String, Age: String, Adress: String, Number: String, Time: String, Music: String, Info: String, Menu: String, More: String) {


        self.HeaderImage = HeaderImage
        self.HeaderTitle = HeaderTitle
        self.Age = Age
        self.Adress = Adress
        self.Number = Number
        self.Time = Time
        self.Music = Music
        self.Info = Info
        self.Menu = Menu
        self.More = More

    }
}

我的BarsTableView看起来像这样:

enter image description here

BarsTableViewController.Swift:

import UIKit


class BarsTableViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate{

    @IBOutlet var tableViewController: UITableView!

    // MARK : Data


    var names = ["Shalvata",
                 "Markid",
                 "Litzman Bar",
                 "The Cat & The Dog",
                 "Light house",

var streets =
    ["האנגר 28,נמל תל אביב",
         "אבן גבירול 30,תל אביב",
        "רחוב נמל תל אביב",
         "קרליבך 28,תל אביב",
         "האנגר 23,נמל תל אביב"]

 var images = [UIImage(named: "Shalvata"),
                  UIImage(named: "Markid"),
                  UIImage(named: "Litzman Bar"),
                  UIImage(named: "CatNDog"),
                  UIImage(named: "LightHouse")]

 override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    {
        return 100.5;
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        ////////

               ////////
    }

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
        let cell = self.tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as! CustomCell
        let user = filteredUsers[indexPath.row]
        cell.photo.image = user.image
        cell.name.text = user.name
        cell.streetName.text = user.streetName


        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.performSegueWithIdentifier("BarsProfile", sender: nil)
    }
}

我没有找到一个教程来展示我真正想要的东西,我希望在这里找到答案因为detailView是每个项目或App的基础。

我不知道如何继续,我对此非常沮丧。

感谢您的帮助:)

1 个答案:

答案 0 :(得分:1)

您可以通过prepareForSegue函数将数据传递到详细信息视图,并在目标视图中设置变量或调用函数。

以下是一个如何完成的示例。这假定您用来呈现详细信息的视图'是类型DetailView和来自您的主人的segue - >细节被称为' BarsProfile':

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if(segue.identifier == "BarsProfile") {
            if(segue.destination is DetailView) {
                let destVC = segue.destination as! DetailView
                // Set variables in Detail View here
                // e.g. :
                destVC.detailData = selectedData
            }
        }
    }