[英]How to overcome of tapping a row in a table
当我点击表格中的一行时,它不会显示下一个屏幕,但是当我点击另一行时,它会显示前一个点击行的详细信息。 如何解决这个问题呢?
class AllListsViewController: UITableViewController {
var lists: [Checklist]
required init(coder aDecoder: NSCoder)
{
lists = [Checklist]()
super.init(coder: aDecoder)
var list = Checklist(name: " Birthdays")
lists.append(list)
list = Checklist( name: "Groceries")
lists.append(list)
list = Checklist(name: "Cool Apps")
lists.append(list)
list = Checklist(name: "To Do")
lists.append(list)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
let checklist = lists[indexPath.row]
performSegueWithIdentifier("ShowChecklist", sender: checklist)
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return lists.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cellIdentifier = "cell"
var cell: UITableViewCell! = tableView.dequeueReusableCellWithIdentifier(cellIdentifier)
if cell == nil
{
cell = UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
}
let checklist = lists[indexPath.row]
cell.textLabel!.text = checklist.name
cell.accessoryType = .DetailDisclosureButton
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowChecklist"
{
let controller = segue.destinationViewController as! ChecklistViewController
controller.checklist = sender as! Checklist
}
}
}
这是我的 didSelectRowAtIndex。
override func tableView (tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
if let cell = tableView.cellForRowAtIndexPath(indexPath)
{
let item = items[indexPath.row]
item.toggleChecked()
configureCheckmarkForCell(cell, withChecklistItem: item)
}
tableView.deselectRowAtIndexPath(indexPath, animated: true)
saveChecklistItems()
}
你搞乱了委托的使用。
您在错误的委托方法中调用performSegueWithIdentifier
,其中行 get's deselected 。
如果你想执行转场,你应该在tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
方法中进行。
目前您正在tableView (tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath)
方法中执行此操作。
这是交换代码后的样子:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
let checklist = lists[indexPath.row]
performSegueWithIdentifier("ShowChecklist", sender: checklist)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.