[英]Passing Data between Table View in Swift
I am trying to pass a data from main table view controller to detail tableview controller. 我试图将数据从主表视图控制器传递到详细表视图控制器。 i am getting lot of rows in my detail with with "label" indicated on it.
我的详细信息中包含很多行,并带有“标签”。 I think i am doing some mistake in specifying the number of rows in a section, but not sure how to fix it.
我认为我在指定节中的行数时犯了一些错误,但不确定如何解决。 any help would be much appreciated.
任何帮助将非常感激。 Thanks in advance
提前致谢
this is how i passed the data from main table view to detail table view 这就是我将数据从主表视图传递到明细表视图的方式
import UIKit
class mainSectionViewController: UIViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var mainSectionTableView: UITableView!
var arrayOfSections : [Sections] = [Sections]()
override func viewDidLoad() {
super.viewDidLoad()
self.setupmainSections()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func setupmainSections() {
var EA503 = Sections (sectionHeader: "Equal Angle", sectionImage: "angle equal.gif", subSection: "50x50x5")
var EA756 = Sections (sectionHeader: "Equal Angle", sectionImage: "angle equal.gif", subSection: "75x75x6")
var UA50403 = Sections (sectionHeader: "Unequal Angle", sectionImage: "angle unequal.gif", subSection: "75x75x6")
var UA90608 = Sections (sectionHeader: "Unequal Angle", sectionImage: "angle unequal.gif",subSection: "90x60x8")
var UC10015 = Sections (sectionHeader: "Universal Column", sectionImage: "Column.gif", subSection: "UC10015")
var UB15015 = Sections (sectionHeader: "Universal Beam", sectionImage: "beam.gif",subSection: "UB15015")
var PFC100 = Sections (sectionHeader: "Parallel Flange Chanel", sectionImage: "PFC.gif", subSection: "PFC100")
var CHS300 = Sections (sectionHeader: "Circular Hollow Section", sectionImage: "chs.gif", subSection: "CHS300")
var SHS200 = Sections (sectionHeader: "Square Hollow Section", sectionImage: "shs.gif",subSection: "SHS200")
var RHS50 = Sections (sectionHeader: "Rectangular Hollow Section", sectionImage: "rhs.gif", subSection: "RHS50")
var EA253 = Sections (sectionHeader: "Equal Angle", sectionImage: "angle equal.gif", subSection: "25x25x3")
arrayOfSections.append(EA503)
arrayOfSections.append(EA756)
arrayOfSections.append(UA50403)
arrayOfSections.append(UA90608)
arrayOfSections.append(UC10015)
arrayOfSections.append(UB15015)
arrayOfSections.append(PFC100)
arrayOfSections.append(CHS300)
arrayOfSections.append(SHS200)
arrayOfSections.append(RHS50)
arrayOfSections.append(EA253)
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let mainsection = arrayOfSections[indexPath.row]
let subsectionViewController : detailSectionViewController = self.storyboard?.instantiateViewControllerWithIdentifier("detailSectionViewController") as detailSectionViewController
subsectionViewController.headerLabelText = mainsection.sectionheader
subsectionViewController.sectionProperties = arrayOfSections
presentViewController(subsectionViewController, animated: true, completion: nil)
}
}
this is my detail table view 这是我的明细表视图
import UIKit
class detailSectionViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchControllerDelegate {
@IBOutlet weak var headerLabel: UILabel!
@IBOutlet weak var subSectionTableView: UITableView!
var headerLabelText : String?
var sectionProperties : [Sections] = [Sections]()
override func viewDidLoad() {
super.viewDidLoad()
self.headerLabel.text = headerLabelText
headerLabel.backgroundColor = UIColor.lightGrayColor()
headerLabel.layer.cornerRadius = 10.0
headerLabel.clipsToBounds = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func prefersStatusBarHidden() -> Bool {
return true
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sectionProperties.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let subCell : detailSectionViewCell = tableView.dequeueReusableCellWithIdentifier("subCell") as detailSectionViewCell
let subsection = sectionProperties[indexPath.row]
if (subsection.sectionheader == headerLabelText) {
subCell.setupSubCell(subsection.subsection)
}
return subCell
}
}
Your problem lies here: 您的问题出在这里:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sectionProperties.count
}
you have assigned: 您已分配:
subsectionViewController.sectionProperties = arrayOfSections subsectionViewController.sectionProperties = arrayOfSections
Well, the arrayOfSections has 11 members. 好吧,arrayOfSections有11个成员。 arrayOfSections.sectionHeader has 8 unique members (but 11 total entries).You are going to have declare a parameter that counts the number of unique sectionHeaders.
arrayOfSections.sectionHeader具有8个唯一成员(但共有11个条目)。您将需要声明一个计算唯一sectionHeaders数量的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.