【发布时间】:2015-09-13 09:15:22
【问题描述】:
我有两个视图控制器 UITableViewController 和 DestinationViewController。 DestinationViewController 的内容应该根据点击的 UITableViewCell 改变。我试过this 教程,但这个没有意义。如何确定点击了哪个单元格以及点击单元格时如何执行 segue?
编辑:
UITableViewController:
let days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
var myIndex: Int?
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
table1View.deselectRowAtIndexPath(indexPath, animated: true)
myIndex = indexPath.row
self.performSegueWithIdentifier("showClassesForSchedule", sender: nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
switch identifier {
case "showClassesForSchedule":
let destinationViewController = segue.destinationViewController as? ScheduleAsClassTableViewController// set here нour destionation VC
if destinationViewController != nil {
destinationViewController?.tableArray.append(days[myIndex!])
destinationViewController?.tableArray = days
print(days[myIndex!])
}
default: break
}
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return days.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("scheduleDaysTextCellIdentifier", forIndexPath: indexPath) as UITableViewCell
let row = indexPath.row
cell.textLabel?.text = days[row]
return cell
}
目标视图控制器:
var tableArray = [String]()
@IBOutlet var table1View: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
print(tableArray)
}
@IBOutlet weak var comingLabelAsNormalView: UILabel!
@IBOutlet weak var comingName: UILabel!
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return tableArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = table1View.dequeueReusableCellWithIdentifier("scheduleDayClassIdentifier", forIndexPath: indexPath) as UITableViewCell
let row = indexPath.row
cell.textLabel?.text = tableArray[row]
return cell
}
【问题讨论】:
标签: ios swift uitableview segue