Reputation: 615
Hello and thank you for your help. I have a custom UITableViewCell and the controller of the class is written in Swift. All of the init functions are being called on creation of the cell however on inspection in the debugger all of the lables and the one image view i have added to the content view have a frame of 0.
here is the file containing the tableView:
class SearchesMainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var contentTableView: UITableView?
var tableViewData = SearchesMainTableViewData()
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
internal override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
override func viewDidLoad(){
super.viewDidLoad()
self.navigationItem.title = "Search"
var nib = UINib(nibName: "SingleSearchTableViewCell", bundle: nil)
contentTableView?.registerNib(nib, forCellReuseIdentifier: SingleSearchTableViewCellController.reuseID())
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return tableViewData.numberOfSectionsInTableView()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableViewData.numberOfRowsInTableSection(section)
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
var cell:SingleSearchTableViewCellController = tableView.dequeueReusableCellWithIdentifier(SingleSearchTableViewCellController.reuseID()) as SingleSearchTableViewCellController
cell.formatCell()
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 54.0
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: false)
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return tableViewData.headerViewForSection(section)
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return tableViewData.heightForTableViewSectionHeaders()
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return tableViewData.heightForTableViewSectionFooters()
}
}
here is the controller for the cell:
class SingleSearchTableViewCellController : UITableViewCell {
@IBOutlet var dateMonthLable : UILabel?
@IBOutlet var dateDayLable : UILabel?
@IBOutlet var yearLable : UILabel?
@IBOutlet var makeModelLable : UILabel?
var search : Search = Search()
class func reuseID() -> String{
return "SingleSearchTableViewCell"
}
required init(coder aDecoder: NSCoder) {
super.init()
}
override init(frame: CGRect) {
super.init(frame: frame)
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
init(previousSearch s : Search){
search = s
super.init()
}
func formatCell(){
formatDateMonthLable()
formatDateDayLable()
formatYearRangeLable()
formatMakeModelLable()
}
private func formatDateMonthLable(){
}
private func formatDateDayLable(){
}
private func formatYearRangeLable(){
}
private func formatMakeModelLable(){
}
}
and an image of the tableview cell in interface builder with all of the bindings:
Thanks a lot for any sugestions or help, I am new with both Swift and interface builder. Have a nice day :)
Edit What is actualy built from this code
It seams like every other place I use nibs there is an initWithNib or something along those lines, and there is nothing like that for tableview cells. I think the linking of data and view may be off or missing something.
Upvotes: 0
Views: 624
Reputation: 104082
The problem is your init overrides in the cell class. I'm not that familiar with Swift, so I don't know why having those in there with nothing but calls to super causes your subview not to show. Since you're not doing anything in those methods (or awakeFromNib either), you should delete them. I think that will fix your problem (it did in my tests).
Upvotes: 1