Table View Cell 没有初始化器
Table View Cell has no Initialiser
我试图在单击按钮时将 table 视图单元格 属性 显示到不同的 table 视图单元格中。我正在使用故事板。我添加了水平和垂直堆栈以包含图像和标签属性。当用户单击显示按钮时,我想将此 属性 显示到另一个 table 视图单元格中。在 cellFor 行函数中,我定义了按钮操作 属性 。我收到以下错误。Class 'DetailsViewCell' 没有初始值设定项。 不能在 属性 初始值设定项中使用实例成员 'mc'; 属性 初始值设定项 运行 在 'self' 可用之前
这是两个视图控制器的屏幕截图。
这是代码。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// guard let cell = tableView.dequeueReusableCell(withIdentifier: MovieCell.identifier, for: indexPath) as? MovieCell
// else { return UITableViewCell() }
let cell = tableView.dequeueReusableCell(withIdentifier: MovieViewCell.identifier, for: indexPath) as! MovieViewCell
cell.showButton.tag = indexPath.row
cell.showButton.addTarget(self, action: Selector("movieDetails"), for: .touchUpInside)
let row = indexPath.row
let title = presenter.getTitle(by: row)
let overview = presenter.getOverview(by: row)
let data = presenter.getImageData(by: row)
cell.configureCell(title: title, overview: overview, data: data)
return cell
}
}
这是标识符 class 中带有 table 视图单元格的代码。
class MovieViewCell: UITableViewCell {
static let identifier = "MovieViewCell"
@IBOutlet weak var mainStackView: UIStackView!
@IBOutlet weak var movieImage: UIImageView!
@IBOutlet weak var movieTtile: UILabel!
@IBOutlet weak var movieOverview: UILabel!
@IBOutlet weak var showButton: UIButton!
@IBAction func movieDetails(_ sender: UIButton) {
var dc : DetailsViewCell
movieTtile = dc.movieTitle
movieOverview = dc.movieOverview
movieImage = dc.movieImage
}
func configureCell(title: String?, overview: String?, data: Data?) {
movieTtile.text = title
movieOverview.text = overview
if let imageData = data{
movieImage.image = UIImage(data: imageData)
}
}
}
这是详细信息视图单元格的代码。
class DetailsViewCell: UITableViewCell {
@IBOutlet weak var movieTitle: UILabel!
@IBOutlet weak var movieOverview: UILabel!
@IBOutlet weak var movieImage: UIImageView!
var mc : MovieViewCell
movieTitle = mc.movieTtile
movieOverview = mc.movieOverview
movieImage = mc.movieImage
}
import UIKit
var loginData = ["", "", ""]
class LoginDataCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var txtLoginData: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func textFieldDidEndEditing(_ textField: UITextField) {
if textField.tag == 0 {
loginData[0] = textField.text
} else if textField.tag == 1 {
loginData[1] = textField.text
} else if textField.tag == 2 {
loginData[2] = textField.text
}
}
}
我试图在单击按钮时将 table 视图单元格 属性 显示到不同的 table 视图单元格中。我正在使用故事板。我添加了水平和垂直堆栈以包含图像和标签属性。当用户单击显示按钮时,我想将此 属性 显示到另一个 table 视图单元格中。在 cellFor 行函数中,我定义了按钮操作 属性 。我收到以下错误。Class 'DetailsViewCell' 没有初始值设定项。 不能在 属性 初始值设定项中使用实例成员 'mc'; 属性 初始值设定项 运行 在 'self' 可用之前
这是两个视图控制器的屏幕截图。
这是代码。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// guard let cell = tableView.dequeueReusableCell(withIdentifier: MovieCell.identifier, for: indexPath) as? MovieCell
// else { return UITableViewCell() }
let cell = tableView.dequeueReusableCell(withIdentifier: MovieViewCell.identifier, for: indexPath) as! MovieViewCell
cell.showButton.tag = indexPath.row
cell.showButton.addTarget(self, action: Selector("movieDetails"), for: .touchUpInside)
let row = indexPath.row
let title = presenter.getTitle(by: row)
let overview = presenter.getOverview(by: row)
let data = presenter.getImageData(by: row)
cell.configureCell(title: title, overview: overview, data: data)
return cell
}
}
这是标识符 class 中带有 table 视图单元格的代码。
class MovieViewCell: UITableViewCell {
static let identifier = "MovieViewCell"
@IBOutlet weak var mainStackView: UIStackView!
@IBOutlet weak var movieImage: UIImageView!
@IBOutlet weak var movieTtile: UILabel!
@IBOutlet weak var movieOverview: UILabel!
@IBOutlet weak var showButton: UIButton!
@IBAction func movieDetails(_ sender: UIButton) {
var dc : DetailsViewCell
movieTtile = dc.movieTitle
movieOverview = dc.movieOverview
movieImage = dc.movieImage
}
func configureCell(title: String?, overview: String?, data: Data?) {
movieTtile.text = title
movieOverview.text = overview
if let imageData = data{
movieImage.image = UIImage(data: imageData)
}
}
}
这是详细信息视图单元格的代码。
class DetailsViewCell: UITableViewCell {
@IBOutlet weak var movieTitle: UILabel!
@IBOutlet weak var movieOverview: UILabel!
@IBOutlet weak var movieImage: UIImageView!
var mc : MovieViewCell
movieTitle = mc.movieTtile
movieOverview = mc.movieOverview
movieImage = mc.movieImage
}
import UIKit
var loginData = ["", "", ""]
class LoginDataCell: UITableViewCell, UITextFieldDelegate {
@IBOutlet weak var txtLoginData: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func textFieldDidEndEditing(_ textField: UITextField) {
if textField.tag == 0 {
loginData[0] = textField.text
} else if textField.tag == 1 {
loginData[1] = textField.text
} else if textField.tag == 2 {
loginData[2] = textField.text
}
}
}