I am trying to create an array of UITableViewCells and before I append the cells I need to initialize them with parameters. When I try to initialize the cell I get an error that the two properties in the class were never defined. But after I defined them I get an error that the variables were used before being initialized. Here is the class
class SimpleCellClassTableViewCell: UITableViewCell {
@IBOutlet var artist: UILabel!
@IBOutlet var picture: UIImageView!
@IBOutlet var songTitle: UILabel!
@IBOutlet var sender: UILabel!
var audioFile: AnyObject? = nil
var mediaType: songType! = nil
var id: NSNumber! = nil
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func configureCell(Title title: NSString?,
File audioFile: AnyObject?,
Type mediaType: songType,
Artist artist: NSString?,
Image image: UIImage?,
Sender sender: NSString?,
ID id: NSNumber?) -> UITableViewCell {
self.audioFile = audioFile
self.mediaType = mediaType
if let newSender = sender{
self.sender.text = newSender as String
}
if let newTitle = title{
self.songTitle.text = newTitle as String
}
if let newImage = image {
self.picture.image = newImage
}
if let newArtist = artist {
self.artist.text = newArtist as String
}
if let newId = id {
self.id = newId as NSNumber
}
return self
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
And this is where Im trying to initialize and then add values to it with configure cell method:
let newSongCell = SimpleCellClassTableViewCell.init(style: .Default, reuseIdentifier: "SimpleCell")
newSongCell.configureCell(Title: setTitle,
File: setAudioFile,
Type: setMediaType,
Artist: setArtist,
Image: setImage,
Sender: setSender,
ID: setId)
The parameters for File and Type are the ones throwing the same error. Also if I need to use the initializer with NSCoder what should I put as the argument?