Was ich erreichen möchte: Ich möchte auf eine der Zeilen in meinem ersten View-Controller klicken, um zu einem anderen Tabellenansicht-Controller zu wechseln.textLabel? .text zeigt nur "Label" an, aber nicht die tatsächlichen Daten aus vorheriger Tabellenansicht
Das Problem: Wenn ich auf die Zeile klicke, zeigt die Ansicht nur "Label" an und nicht die Daten, die ich durchgehen möchte. Wenn die Anwendung nicht abstürzt und der weiße Hintergrund mit der Überschrift "Label" angezeigt wird, werden die Daten auf dem Controller der 2. Ansicht immer noch nicht angezeigt.
Was ich so getan habe ffar: Ich habe ein Struct: PageTwoItems verwendet, um die Daten zu definieren, die ich an den 2. View Controller senden möchte.
import Foundation
import UIKit
Der Code für die zweite View-Controller ist wie folgt:
@IBOutlet weak var tableView: UITableView!
let names = ["Cleaning", "Plumbing","Electrical", "Craftswork", "Automotive"]
let desc = ["Get your spotless home or office space", "Drains, Pipes, Faucets and more", "Lighting, Fans, AC's and more", "Installation, Assembly and more", "Tow Truck Hire, Tyre Replacement and more"]
let images = [UIImage(named:"pug"),UIImage(named:"pug2"),UIImage(named:"pug3"),UIImage(named:"pug4"),UIImage(named:"pug5")]
var PageTwo = [PageTwoItems]()
override func viewDidLoad() {
PageTwo = [PageTwoItems(nametwo:["Home Cleaning", "Office Cleaning", "Moving In/Out Cleaning"], summarytwo:["Let your home sparkle","Office space cleaning right at your fingertips","New Home or Old Home? We've got you covered"],phototwo:["","",""]),
PageTwoItems(nametwo:["Drains, Pipes & Faucets", "Showers and Bath Tubs", "Toilet and Wash Basin", "Water Heater"], summarytwo:["Fix Your Broken Pipes, Clogged Drains and Leaky Faucets","Showers and Bath Tubs working just right"," ", " "],phototwo:["","",""]),
PageTwoItems(nametwo:["Lighting Fixtures", "Air Conditioners & Fans", "Generators"], summarytwo:["..","..",".."],phototwo:["","",""]),
PageTwoItems(nametwo:["Furniture Assembly/Installation", "Interior Painting", "Doors, Windows & Curtains"], summarytwo:["..","...","..."],phototwo:["","",""]),
PageTwoItems(nametwo:["Tow Truck Hire", "Tyre/Vulcanizer Help", "Auto-Consultant"], summarytwo:["...","...","..."],phototwo:["","",""])]
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("newcell", forIndexPath:indexPath) as!CustomCell
cell.photo.image = images[indexPath.row]
cell.summary.text = desc[indexPath.row]
cell.name.text = names[indexPath.row]
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let indexPath : NSIndexPath = self.tableView.indexPathForSelectedRow!
let DestViewController = segue.destinationViewController as! PageTwoTableViewController
var PageTwoArrayTwo : PageTwoItems
PageTwoArrayTwo = PageTwo[indexPath.row]
DestViewController.PageTwo = PageTwoArrayTwo.nametwo
DestViewController.PageTwo = PageTwoArrayTwo.summarytwo
DestViewController.PageTwo = PageTwoArrayTwo.phototwo
}
}
:class PageTwoTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var PageTwo = [String]()
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return PageTwo.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let Cell = self.tableView.dequeueReusableCellWithIdentifier("secondcell", forIndexPath: indexPath) as UITableViewCell
Cell.textLabel?.text = PageTwo[indexPath.row]
return Cell
}
}
Der Code für den ersten View-Controller wie folgt ist
The struct for the Page Two Items:
struct PageTwoItems {
var nametwo : [String]
var summarytwo : [String]
var phototwo : [String]
}
Haben Sie die Delegierten und die Datenquelle Ihrer Tableview in der 2. Controller? Wenn ja, haben Sie den Wert von PageTwo [indexPath.row] überprüft? – Ro22e0
@ Ro22e0 ja Ich habe den Delegaten und die Datenquelle der Tabellenansicht im 2.Controller eingestellt. Ich bin relativ neu bei der schnellen Codierung von Bro. Wie kann ich nach dem Wert von PageTwo [indexPath.row] suchen? –