Ios 填充Tableview时发送到实例的选择器无法识别
当我尝试在视图控制器中填充tableview时,会出现以下错误:[UITableViewCellContentView\u isResizable]:未识别的选择器发送到实例Ios 填充Tableview时发送到实例的选择器无法识别,ios,swift,uitableview,Ios,Swift,Uitableview,当我尝试在视图控制器中填充tableview时,会出现以下错误:[UITableViewCellContentView\u isResizable]:未识别的选择器发送到实例 import UIKit import CoreLocation class FirstViewController: UIViewController, CLLocationManagerDelegate, UITableViewDelegate, UITableViewDataSource{ @IBOu
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
这是由于在
数组中使用的对象名称与和cellForRowAtIndexPath:
您正在数组中的对象Photo
中设置图像名称,但在cellForRowAtIndexPath:
另外,正如@Usama所说,您正在初始化一个新的UIImageView
。因此,这里不需要创建新的UIImageView
,只需将图像
分配给现有图像即可
替换代码
myCellToReturn.Imago = UIImageView(image: Locali[indexPath.row].Image)
与
非常感谢。我更改了该行,它运行没有问题,但是tableview没有填充,您可以找出原因吗?确认Locali
中是否有元素您实现了heightforrowatinexpath
方法?它在视图控制器中初始化,它怎么可能为空?是的,我实现了它以返回原型页面的高度
myCellToReturn.Imago.image = UIImage(named: Locali[indexPath.row].Photo)