ios - 填充 Tableview 时发送到实例的无法识别的选择器

标签 ios swift uitableview

当我尝试在 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/

相关文章:

ios - drawPageAtIndex 在 iOS 8.1.1 中挂起

ios - Appcelerator - 由于缺少 plist 键,iOS 应用程序被拒绝

ios - iOS 的 Cordova 应用程序构建失败 ** 存档失败 **

ios - 核心数据 NSManagedObjectContext 与 NSMergePolicyType - 崩溃

iOS - 如何对深层链接进行单元测试以确保它们可以在应用程序端进行处理

ios - 执行 UIAlertController 实例时,在单个文本字段对象上多次触发 textFieldShouldEndEditing 委托(delegate)方法

ios - 从导航 Controller 的任何 subview 返回登录屏幕

ios - UITableViewCell 的 backgroundView 从 UITableView 的左边缘偏移

ios - 调用-reloadData后如何保持UITableView contentoffset

uitableview - 将 UITableViewCell 中的 subview 置于前面