我遇到了查看控制器的问题。我有xib表视图单元格的表视图。这是我的代码。
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
setupTableView()
setupDataSource()
}
private func setupTableView() {
tableView.backgroundColor = UIColor.clearColor()
tableView.allowsSelection = false
tableView.separatorColor = UIColor.clearColor()
tableView.registerNib(UINib(nibName: "ExampleTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! ExampleTableViewCell
let list = pariwisata[indexPath.row]
cell.nameLabel.text = list.name
cell.typeLabel.text = list.type
let image = objects[indexPath.row]
cell.apply(image)
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Row \(indexPath.row) selected")
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return tableView.bounds.width / 1.4
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
updateLocation(true)
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
updateLocation(false)
updateLocation(true)
}
func updateLocation(running: Bool) {
let mapView = self.view as! GMSMapView
let status = CLLocationManager.authorizationStatus()
if running {
if (CLAuthorizationStatus.AuthorizedWhenInUse == status) {
locationManager.startUpdatingLocation()
mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true
}
} else {
locationManager.stopUpdatingLocation()
mapView.settings.myLocationButton = false
mapView.myLocationEnabled = false
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "showTop10Detail" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let destinationController = segue.destinationViewController as! DetailViewController
destinationController.detpariwisata = pariwisata[indexPath.row]
}
}
构建项目时没有错误,但我无法点击我的表格视图。我的意思是,我可以点击我的桌面视图,但它什么都不打印。我错过了什么?请给我一些线索。谢谢!
答案 0 :(得分:1)
1)您必须删除:
tableView.allowsSelection = false
2)使用此行从一个单元格传递到另一个单元格(例如 DetailPage ):
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("toDetailPage", sender: indexPath)
}
3)使用此方法将数据传递到 DetailPage :
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let indexPath = self.tableView.indexPathForSelectedRow
let person = personList[indexPath!.row]
if segue.identifier == "toDetailPage"{
let DetailBookViewController = (segue.destinationViewController as! DetailPage)
DetailBookViewController.user_name = user_name
DetailBookViewController.user_age = user_age
DetailBookViewController.user_urlPicture = user_urlPicture
}
4)记住:
在您的故事板中,您必须将 tableViewController 与 DetailPage
您必须为Person
声明一个类并声明:
var PersonList = [Person]()
您必须在var
课程和tableView
课程中声明DetailPage
答案 1 :(得分:0)
删除这行代码:
tableView.allowsSelection = false
不允许选择细胞。