ios - Master-DetailView 应用程序

标签 ios iphone swift uitableview master-detail

我正在尝试创建主细节 View 应用程序,但有点卡住了。

我有一个包含 100 个 DynamicPrototype Cells 的 tableView 显示 Bars,当我点击一个 cell 时,我想显示有关该 Bar 的更多信息.

我的问题是如何将不同的data(如labelsimages)填充到DetailView 中并将它们更改为我点击的每个 cell 代表正确的 data

我的 Detailview 是一个带有 StaticCellsTableViewController,如下所示:

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 是每个项目或应用程序的基础。

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

感谢您的帮助:)

最佳答案

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

这是一个如何完成的示例。这假设您用来呈现“细节”的 View 属于 DetailView 类型,并且来自您的 master -> Detail 的 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
            }
        }
    }

关于ios - Master-DetailView 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40711251/

相关文章:

iphone - 如何在 iOS 中为 uibutton 的文本和颜色添加下划线

iphone - 从 iPhone 应用程序上传图像

java - 如何在 Android(Java) 中使用 json 反斜杠

ios - 如何在运行时每 0.2 秒在屏幕上的不同位置重新创建屏幕上的相同节点?

ios - 在 Swift 中使用 uiimagePickerController 在同一 View Controller 中选取两个不同的图像

ios - 作为承包商发布企业应用程序,其中证书和配置文件

iPhone/iOS : Best practices to shorten launch time of an app?

ios - 删除单元格后刷新tableView

objective-c - 向 MKMapView 添加多个叠加层

javascript - 在网络应用程序中检测 iPhone 4 vs 4s - PhoneGap