DetailView与静态单元格

时间:2016-11-17 23:43:22

标签: ios iphone swift master-detail detailview

我正在尝试创建一个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

    }
}

感谢您的帮助:)

2 个答案:

答案 0 :(得分:1)

非常简单,您只考虑在headerTitle中显示viewController1,如果您在detailTableViewController中选择任何一行,您将要显示age,{{1 }和address(您可以通过创建额外的静态单元格并在其中放置标签来显示您想要的任何内容。)

您修改过的课程:

首先将所有属性声明为init()方法中的可选和可选

number

像往常一样填充import Foundation class BarProfile { var HeaderImage: String? var HeaderTitle: String? var Age: String? var Adress: String? var Number: String? var Time: String? var Music: String? var Info: String? var Menu: String? var More: String? 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 } } 表格视图,当用户点击所选对象的任何单元格传递到ViewController1时。从detailTableViewControllerViewController1的表格视图单元格创建segue。

ViewController1中的代码:

detailTableViewController

detailTableViewController中的代码:

class viewController1: UIViewController, UITableViewDataSource, UITableViewDelegate {

var barArray:[BarProfile] = []
var selctedIndexPath: NSIndexPath?

override func viewDidLoad() {
    super.viewDidLoad()
    for _ in 0...5 { // Creating dummy object for clear understanding. 
        let barObject = BarProfile(HeaderImage: "werw", HeaderTitle: "erqwrw", Age: "34", Adress: "qwerwer", Number: "32", Time: "time", Music: "qerqw", Info: nil, Menu: nil, More: nil)
        barArray.append(barObject)
    }
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return barArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell Identifier")! as UITableViewCell
    cell.textLabel?.text = barArray[indexPath.row].HeaderTitle
    return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    selctedIndexPath = indexPath
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
// MARK: Navigation Methods

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "SegueIdentifier" {
        let detailViewController = segue.destinationViewController as? detailTableViewController
        detailViewController?.selectedBarObject = barArray[(selctedIndexPath?.row)!]
    }
}

}

感谢:)

答案 1 :(得分:0)

Shalom,实际上非常简单:

您的详细视图似乎也是一个表格视图。因此,以与其他表视图相同的方式实现。

返回你的8个单元格,并创建不同的单元格原型(从上面的截图中,你似乎需要三个左右)。在cellForRowAtIndexPath中,检查您所在的行,并使用正确的图像和BarProfile对象(应该是视图控制器的ivar)中的正确数据字段填充单元格。

图片和标题可以实现为tableHeaderView