10.Silver Challenge

override func viewDidLoad() {
super.viewDidLoad()

    let statusBarHeight = UIApplication.shared.statusBarFrame.height
    let insets = UIEdgeInsetsMake(statusBarHeight, 0, 0, 0)
    tableView.contentInset = insets
    tableView.scrollIndicatorInsets = insets

// add footer to always show No more item
let footer = UITableViewCell()
footer.textLabel?.text = "No More Items"
tableView.tableFooterView = footer

    }

I went for adding this to ItemsViewController

    override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {

    return "No More Items"
    
}

Hi,

thanks for the solution and it works fine but it was asked to make last row as “No more items” but in you solution it is footer not row(since gold challenge is also related to silver), please help

I went with adding a footer as well. The solution I came up with is . . . a little verbose:

override func viewDidLoad() {
    super.viewDidLoad()

    //Get the height of the status bar
    let statusBarHeight = UIApplication.shared.statusBarFrame.height
    
    let insets = UIEdgeInsets(top: statusBarHeight, left: 0, bottom: 0, right: 0)
    tableView.contentInset = insets
    tableView.scrollIndicatorInsets = insets
    
    let footerView = UIView()
    let footColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)
    footerView.backgroundColor = footColor
    footerView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 44)
    let footLabel = UILabel()
    footLabel.text = " No more items!"
    footerView.addSubview(footLabel)
    footLabel.topAnchor.constraint(equalTo: footerView.topAnchor).isActive = true
    footLabel.bottomAnchor.constraint(equalTo: footerView.bottomAnchor).isActive = true
    footLabel.leftAnchor.constraint(equalTo: footerView.leftAnchor).isActive = true
    footLabel.rightAnchor.constraint(equalTo: footerView.rightAnchor).isActive = true
    footLabel.translatesAutoresizingMaskIntoConstraints = false
    tableView.tableFooterView = footerView
}