当我尝试在 View Controller 中填充表格 View 时,出现此错误:[UITableViewCellContentView _isResizable]:无法识别的选择器发送到实例
import UIKit
import CoreLocation
class FirstViewController: UIViewController, CLLocationManagerDelegate, UITableViewDelegate, UITableViewDataSource{
@IBOutlet var citta: AutoCompleteTextField!
@IBOutlet var tableView: UITableView!
let locationManager = CLLocationManager()
var locality : String = ""
var Locali = [Locale(Name: "Prova1", Address: "Via Prova ,1", Citta: "Bologna",Photo: UIImage(named: "Fav")!),Locale(Name: "Prova1", Address: "Via Prova ,1", Citta: "Bologna",Photo: UIImage(named: "Fav")!),Locale(Name: "Prova1", Address: "Via Prova ,1", Citta: "Bologna",Photo: UIImage(named: "Fav")!),Locale(Name: "Prova1", Address: "Via Prova ,1", Citta: "Bologna",Photo: UIImage(named: "Fav")!)]
override func viewDidLoad() {
super.viewDidLoad()
self.tableView!.delegate = self
self.tableView!.dataSource = self
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks,error) -> Void in
if error != nil{
print("Error : " + error!.localizedDescription)
return
}
if placemarks!.count > 0{
let pm = placemarks![0]
self.displayLocationInfo(pm)
}})
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Error:" + error.localizedDescription)
}
func displayLocationInfo(placemarks: CLPlacemark)
{
self.locationManager.stopUpdatingLocation()
self.citta.text = placemarks.locality!
}
func tableView(tableView : UITableView, numberOfRowsInSection section : Int) -> Int{
return Locali.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)->UITableViewCell{
let myCellToReturn = self.tableView.dequeueReusableCellWithIdentifier("Local_Cell", forIndexPath: indexPath) as! Local_Cell
myCellToReturn.Nome?.text = Locali[indexPath.row].Name
myCellToReturn.Address?.text = Locali[indexPath.row].Address
myCellToReturn.Imago = UIImageView(image: Locali[indexPath.row].Image)
return myCellToReturn
}
}
Locale 是我的自定义对象,Local_Cell 是我的自定义单元格,这是代码:
import UIKit
class Local_Cell: UITableViewCell {
@IBOutlet var Nome: UILabel!
@IBOutlet var Imago: UIImageView!
@IBOutlet var Address: UILabel!
@IBOutlet var Fav_Button: UIButton!
@IBOutlet var Menu_Button: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
我尝试了一切,谁能告诉我我做错了什么?
最佳答案
问题出在这行代码上:
myCellToReturn.Imago = UIImageView(image: Locali[indexPath.row].Image)
Imago
是一个 IBOutlet
那么为什么要实例化一个新的 UIImageView
并将其分配给 Imago
试试这个
myCellToReturn.Imago.image = Locali[indexPath.row].Image
关于ios - 填充 Tableview 时发送到实例的无法识别的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33826469/