大佬教程收集整理的这篇文章主要介绍了swift – 认为没有选择行号,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
因此,在搜索Web之后,我设置了变量indexOfSELEctedPerson,该变量被赋予indexPath.row的值.我在模拟器中运行应用程序时的问题是prepareForSegue获取indexOfSELEctedPerson(0)的初始值,然后在我单击它之后获取所选行的值.因此,当我点击模拟器中的后退按钮并选择另一行时,详细视图会显示我上一次选择的行的信息.
import UIKit class MasterTableViewController: UITableViewController { var people = [] var indexOfSELEctedPerson = 0 override func viewDidLoad() { super.viewDidLoad() people = ["Bob","Doug","Jill"] } override func numberOfSectionsInTableView(tableView: UITableView?) -> Int { return 1 } override func tableView(tableView: UITableView?,numberOfRowsInSection section: int) -> Int { return people.count } override func tableView(tableView: UITableView!,cellForRowATindexPath indexPath: NSIndexPath!) -> UITableViewCell! { let cell = tableView!.dequeueReusableCellWithIdentifier("personCell",forIndexPath: indexPath) as UITableViewCell cell.text = "\(people[indexPath.row])" return cell } override func tableView(tableView: UITableView!,didSELEctRowATindexPath indexPath: NSIndexPath!) { indexOfSELEctedPerson = indexPath.row } override func prepareForSegue(segue: UIStoryboardSegue!,sender: AnyObject!) { if let mySegue = segue.identifier { if mySegue == "personDetails" { let detailsVC: DetailTableViewController = segue.desTinationViewController as DetailTableViewController detailsVC.SELEctedPersonName = "\(people[indexOfSELEctedPerson])" } } } }
因此,当应用程序首次在模拟器中启动时选择Doug会显示Bob的详细信息,因为indexPathOfSELEctedPerson为0.按下后退按钮然后选择Jill会显示Doug的详细信息,因为当我上一次单击Doug时indexPathOfSELEctedPerson变为1.我猜测问题源于调用方法的顺序.
以上是大佬教程为你收集整理的swift – 认为没有选择行号全部内容,希望文章能够帮你解决swift – 认为没有选择行号所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。