我不能在uitableviewcell做出口

时间:2016-06-26 13:03:32

标签: ios swift uitableview

我不想让我的代码变得凌乱,所以我为表格视图单元格创建了一个单独的类,但当我尝试创建UIImageView的出口时,它显示错误

import UIKit
class TableViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

@IBOutlet var image: UIImageView!

}

//我的tableview的代码

import UIKit

class ViewController: UIViewController, UITableViewDelegate,UITableViewDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    var array = ["apple","blue_graps","cherry","grape","Pineapple","pomegranate","Strawberry"]

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
        cell.imageView?.image = UIImage(named: array[indexPath.row])
        return cell
    }


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


      return  array.count

    }
}

enter image description here

1 个答案:

答案 0 :(得分:2)

将变量image更改为其他名称,例如myImageicon

UITableViewCell中有一个名为image的已弃用属性,您无法重新声明它。 (它已经在iOS 3中弃用了,但它仍然存在)。