gpt4 book ai didi

ios - 继续错误 "Ambigious Reference to member ' tableView'“Swift

转载 作者:行者123 更新时间:2023-11-28 11:09:08 26 4
gpt4 key购买 nike

当我想向我的 View Controller 添加一个 segue 时,我在 prepare for segue 函数中不断收到这个错误。这是错误:“Ambigious Reference to member 'tableView'”

这是我的代码:

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "showCountryDetails" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let destinationController = segue.destinationViewController as!
DetailViewController
destinationController.countryImage = self.photos[indexPath.row]
} }
}

TravelTableViewController.swift

import UIKit

class TravelTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var countries = ["Qatar","Brazil","United Kindgom","KSA"]
var cities = ["Doha","Rio","London","Riyadh"]
var photos = ["Qatar.jpg","Rio.jpg","Lndn.jpg","KSA.png"]

var countryIsVisited = [Bool](count: 4, repeatedValue: false)
var countryIsNotVisited = [Bool](count: 4, repeatedValue: false)




override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return countries.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath:indexPath) as!TravelTableViewCell

cell.CityLabel.text = cities[indexPath.row]
cell.CountryLabel.text = countries[indexPath.row]
cell.ImageLabel.image = UIImage(named: photos[indexPath.row])

cell.ImageLabel.layer.cornerRadius = cell.ImageLabel.frame.size.width / 2
cell.ImageLabel.clipsToBounds = true

if countryIsVisited[indexPath.row] {
cell.accessoryType = .Checkmark
}

else{
cell.accessoryType = .None
}

return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let optionMenu = UIAlertController(title: nil, message: "What do you want to do ?", preferredStyle: .ActionSheet)

let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
optionMenu.addAction(cancelAction)

self.presentViewController(optionMenu,animated: true, completion: nil)


let callActionHandler = { (action:UIAlertAction!) -> Void in
let alertMessage = UIAlertController(title: "Service Unavailable", message: "Sorry the phone is not avilable at the mometn", preferredStyle: .Alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(alertMessage, animated: true, completion: nil)
}

let callAction = UIAlertAction(title: "Call " + "123-000-\(indexPath.row)", style:
UIAlertActionStyle.Default, handler: callActionHandler)
optionMenu.addAction(callAction)

let isVisitedAction = UIAlertAction(title: "I've been here", style: .Default, handler: {
(action:UIAlertAction!) -> Void in
let cell = tableView.cellForRowAtIndexPath(indexPath)

let checkImage = UIImage(named: "Hearts-48.png")
let checkMark = UIImageView(image: checkImage)
cell?.accessoryView = checkMark
self.countryIsVisited[indexPath.row] = true
})
optionMenu.addAction(isVisitedAction)

let isNotVisitedAction = UIAlertAction(title: "I haven't been here", style: .Default, handler: {
(action:UIAlertAction!) -> Void in
let cell = tableView.cellForRowAtIndexPath(indexPath)
cell?.accessoryView = .None
self.countryIsNotVisited[indexPath.row] = true
})
optionMenu.addAction(isNotVisitedAction)





}





func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title:
"Share", handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in


let shareMenu = UIAlertController(title: nil, message: "Share using",
preferredStyle: .ActionSheet)
let twitterAction = UIAlertAction(title: "Twitter", style:
UIAlertActionStyle.Default, handler: nil)
let facebookAction = UIAlertAction(title: "Facebook", style:
UIAlertActionStyle.Default, handler: nil)
let emailAction = UIAlertAction(title: "Email", style: UIAlertActionStyle.Default,
handler: nil)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel,
handler: nil)
shareMenu.addAction(twitterAction)
shareMenu.addAction(facebookAction)
shareMenu.addAction(emailAction)
shareMenu.addAction(cancelAction)



self.presentViewController(shareMenu, animated: true, completion: nil)
} )
let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default,
title: "Delete",handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
// Delete the row from the data source
self.countries.removeAtIndex(indexPath.row)
self.cities.removeAtIndex(indexPath.row)
self.photos.removeAtIndex(indexPath.row)

tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)



} )


//Adding Background Color to the Delete and Share Button
shareAction.backgroundColor = UIColor(red: 255.0/255.0, green: 166.0/255.0, blue:
51.0/255.0, alpha: 1.0)
deleteAction.backgroundColor = UIColor(red: 51.0/255.0, green: 51.0/255.0, blue:
51.0/255.0, alpha: 1.0)


return [deleteAction, shareAction]


}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "showRestaurantDetail" {
if let indexPath = self.tableView.indexPathForSelectedRow() {
let destinationController = segue.destinationViewController as!
DetailViewController
destinationController.countryImage = self.photos[indexPath.row]
} }
}

}

最佳答案

tableView 的连接导出在哪里?似乎您的代码没有它。从 Storyboard 中按住 Control 并拖动(如果您正在使用它们),您的错误应该会消失。

关于ios - 继续错误 "Ambigious Reference to member ' tableView'“Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36130224/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com