0

The rest of a custom table view cell is not showing up for me in a table view. Only the very top part of the custom table view cell is showing.

The custom table view cell that this is occurring for is for showing the open business hours of a user-selected restaurant. Also, the particular custom table view cell to be showed for this row in the table view thats for showing the open business hours of the selected custom table view cell is decided through a switch-case statement in a separate function that's in a separate file.

The only things that are showing from the custom table view cell is the open business hours for the first day of the week that I use for this table view cell (which is Sunday).

Screenshot of what the table view cell that this problem is occurring for currently looks like

Screenshot of what the table view cell that this problem is occurring for currently looks like

Screenshot of an example of what the UI should like for this table view cell

Screenshot of an example of what the UI should like for this table view cell

*Note: This picture doesn't show the actual open business hours time ranges that should be displayed for the selected restaurant that I've been testing my code/project with; it's just an example of what the UI should look like.

I’m not using Main.storyboard for showing/connecting the view controller that has this custom table view cell I’m having problems with here, but it is shown in the Main.storyboard file. Instead, I'm presenting this view controller that has the custom table view cell I’m having problems with in another view controller which is accessed/ran before (the user uses the view from this view controller before the view controller that has the custom table view cell that I'm having problems with) via code.

The code that presents the view controller that has the custom table view cell that I'm having problems with:

CitiesRestaurantsResultsViewController.swift

//*Code for a view controller that has a table view.*

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        //Presenting Details view as a table view.
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let scrollableCitiesRestaurantDetailsVC = storyboard.instantiateViewController(identifier: "ScrollableCitiesRestaurantDetailsViewController") as! ScrollableCitiesRestaurantDetailsViewController
        scrollableCitiesRestaurantDetailsVC.modalPresentationStyle = .fullScreen
        scrollableCitiesRestaurantDetailsVC.modalTransitionStyle = .crossDissolve

        scrollableCitiesRestaurantDetailsVC.venues = venues[indexPath.row]

        navigationController?.pushViewController(scrollableCitiesRestaurantDetailsVC, animated: true)
    }

//*Rest of code for this view controller file includes extensions and one class definition which are all unrelated to the current problem I'm having which this post is about.*

*Also, Note: I have the labels for the open business hours time ranges for each day of the week in this table view cell's .xib file that I'm having trouble with, set to being empty; there is no text entered into these labels at this time, and when I've been running my code/program.

What I’ve tried/checked:

  • Whether the table view cell’s height for the custom table view cell that’s giving me this problem is the correct value in that custom table view cell's .xib file. It is.

  • Whether the correct custom class is selected for this custom table view cell, and whether the Module that is selected is correct, and that the “Inherit Module From Target” checkbox is checked, all in the Identity inspector panel in this custom table view cell's .xib file. All of these settings are correct.

  • Whether the "Style" is set to "Custom", and that the correct "Identifier" is set for the table view cell in the Attributes inspector, in the table view cell's .xib file. Both of these settings are correct.

I’ve also researched solutions online, however, their solutions didn’t work for me. I'd post them here, however I was getting error messages saying this post looked like spam when I included them.

How do I solve this problem?

I’ve posted the code below.

Thanks!

Code:

ScrollableCitiesRestaurantDetailsViewController.swift:

import UIKit
//*More import statements.*

class ScrollableCitiesRestaurantDetailsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet var scrollableCitiesRestaurantDetailsTableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //*Code for registering the custom table view cells used for this table view.*
        
        scrollableCitiesRestaurantDetailsTableView.delegate = self
        scrollableCitiesRestaurantDetailsTableView.dataSource = self
        
        //*Code for getting the data from the API.*
        
    }

    //*More generic code for this table view.*
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 11
        
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if indexPath.row == 0 {
            
            //*Code for this cell goes here.*
            
            return custumCell
        }
        
        //*More "indexPath.row" code goes here for other table view cells being used. This is for showing the name of the restaurant, the address of the restaurant, etc..*
        
        if indexPath.row == 10 {
            
            return getBusinessHoursTimeRangesForDaysOfWeekTableViewCellToBeUsedForDetailViewFromListView(amountOfTimeRanges: selectedVenueDetailViewInfo.hours.numberOfOpenHoursTimeRangesAsStringTypeOfTableViewCellToUse, indexPathFromScrollableCitiesRestaurantDetailsViewController: indexPath)
        }
        
        //Need below code so shows table view correctly, even though below code isn't technically shown in table view.
        let cell = scrollableCitiesRestaurantDetailsTableView.dequeueReusableCell(withIdentifier: "DetailsTitleTableViewCell", for: indexPath) as! DetailsTitleTableViewCell

        cell.restaurantNameLabel.text = String(indexPath.row)

        return cell
        
    }
}

//*Some Extensions.*

GetSelectedRestaurantOpenHoursTableViewCellToBeUsed-ExtensionOfScrollableCitiesRestaurantDetailsViewController.swift:

import UIKit
import Foundation

extension ScrollableCitiesRestaurantDetailsViewController {
    
    func getBusinessHoursTimeRangesForDaysOfWeekTableViewCellToBeUsedForDetailViewFromListView(amountOfTimeRanges: String, indexPathFromScrollableCitiesRestaurantDetailsViewController: IndexPath) -> UITableViewCell {
        
        switch amountOfTimeRanges {
        
        case "OneTimeRange":
            
            let detailsHoursContentsCustomCell = scrollableCitiesRestaurantDetailsTableView.dequeueReusableCell(withIdentifier: "DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell", for: indexPathFromScrollableCitiesRestaurantDetailsViewController) as! DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell
            
            detailsHoursContentsCustomCell.sundayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.sundayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.mondayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.mondayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.tuesdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.tuesdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.wednesdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.wednesdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.thursdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.thursdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.fridayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.fridayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.saturdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.saturdayOpenHoursWithoutDay

            return detailsHoursContentsCustomCell
            
        case "TwoTimeRanges":
            
            let detailsHoursContentsCustomCell = scrollableCitiesRestaurantDetailsTableView.dequeueReusableCell(withIdentifier: "DetailsHoursContentsForAtLeastOneDayWithTwoOpenCloseTimeRangePairsTableViewCell", for: indexPathFromScrollableCitiesRestaurantDetailsViewController) as! DetailsHoursContentsForAtLeastOneDayWithTwoOpenCloseTimeRangePairsTableViewCell
            
            detailsHoursContentsCustomCell.sundayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.sundayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.mondayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.mondayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.tuesdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.tuesdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.wednesdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.wednesdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.thursdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.thursdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.fridayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.fridayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.saturdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.saturdayOpenHoursWithoutDay

            return detailsHoursContentsCustomCell
            
        default:
            
            let detailsHoursContentsCustomCell = scrollableCitiesRestaurantDetailsTableView.dequeueReusableCell(withIdentifier: "DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell", for: indexPathFromScrollableCitiesRestaurantDetailsViewController) as! DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell

            detailsHoursContentsCustomCell.sundayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.sundayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.mondayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.mondayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.tuesdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.tuesdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.wednesdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.wednesdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.thursdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.thursdayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.fridayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.fridayOpenHoursWithoutDay
            detailsHoursContentsCustomCell.saturdayHoursOpenWithoutDayLabel.text = selectedVenueDetailViewInfo.hours.saturdayOpenHoursWithoutDay

            return detailsHoursContentsCustomCell
    }
    }
}

The custom table view cell that I'm having problems with's .swift file:

DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell.swift:

import UIKit

class DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell: UITableViewCell {

    static let identifier = "DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell"
    
    static func nib() -> UINib {
        return UINib(nibName: "DetailsHoursContentsForAllDaysWithOneOpenCloseTimeRangePairTableViewCell", bundle: nil)
    }
    
    //IBOutlets
    @IBOutlet var sundayHoursOpenWithoutDayLabel: UILabel!
    @IBOutlet var mondayHoursOpenWithoutDayLabel: UILabel!
    @IBOutlet var tuesdayHoursOpenWithoutDayLabel: UILabel!
    @IBOutlet var wednesdayHoursOpenWithoutDayLabel: UILabel!
    @IBOutlet var thursdayHoursOpenWithoutDayLabel: UILabel!
    @IBOutlet var fridayHoursOpenWithoutDayLabel: UILabel!
    @IBOutlet var saturdayHoursOpenWithoutDayLabel: UILabel!
    
    var selectedVenueDetailViewInfo: SelectedRestaurantDetailViewInfo!

    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
    }
    
}
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
cg1000
  • 7
  • 4
  • It looks like a row height thing. From what I can see your custom cell is being used, but you can only see the top part of it. Implement the height for row delegate method and return a height large enough for the cell to be shown. If that doesn't work, then you probably have some issue with layout constraints in the cell's xib file. – jrturton Jun 24 '23 at 08:49
  • @jrturton Thanks, I will try this. I had considered this earlier, but I had thought that the height in the heightForRowAt delegate method had to be a constant/only be one value, and I need there to be an option of two values that can be selected and used based on which custom table view cell for the different amount of open business hours time ranges is selected. Although I think I’ve thought of a way to do this after your suggestion. Thanks, I’ll get back to you! – cg1000 Jun 24 '23 at 16:19

0 Answers0