我正在尝试将数据从“事件”表视图的选定单元格传递到“详细信息”视图控制器。我已经查看了类似于我的各种问题,但我似乎无法将其正确应用到我的代码中。我也使用标签,而不是字幕样式。还有一个需要传递的图像。
我的视图控制器如下所示:
$(document).on('click', '#<%=link.ClientID%>', function (event) {
event.preventDefault();
});
这是我的customCell.swift文件:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
var names = ["BTown Diner", "Dunnkirk", "Chocolate Mousse", "Lil Wayne", "Annie", "Campus Squad Social"]
var details = ["Free drink with meal after 12 AM", "LADIES drink free", "10% off all ice cream!", "Lil 500 concert", "an IU Theater Production", "Bring your Squad to the Campus Squad Social"]
var images = [UIImage(named: "btown"), UIImage(named: "dunn"), UIImage(named: "choco"), UIImage(named: "lilwayne"), UIImage(named: "default"), UIImage(named: "default")]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomCell
cell.name.text = names[indexPath.row]
cell.detail.text = details[indexPath.row]
cell.photo.image = images[indexPath.row]
return cell
}
var valueToPass:String!
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("You selected cell #\(indexPath.row)!")
// Get Cell Label
let indexPath = tableView.indexPathForSelectedRow();
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;
valueToPass = currentCell.textLabel.text
performSegueWithIdentifier("detailsSegue", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "detailsSegue") {
// initialize new view controller and cast it as your view controller
var viewController = segue.destinationViewController as detailsViewController
// your new view controller should have property that will store passed value
viewController.passedValue = valueToPass
}
}
}
我对Swift很新,事实证明这对我来说非常具有挑战性。我真的不是一个程序员,但是一个项目要求我完成一些应用程序的编码,我是UI / UIX的设计者。提前谢谢你的帮助!