cellForRowAt не вызывается при использовании titleForHeaderInSection - PullRequest
0 голосов
/ 12 июля 2020

Итак, когда я использую titleForHeaderInSection метод, cellForRowAt не вызывается, что означает, что cellForRow ( at: IndexPath) возвращает nil в модульном тесте. Однако, когда я не вызываю titleForHeaderInSection , выполняется cellForRowAt , и все работает нормально. Это приводит к сбою всех моих модульных тестов, основанных на cellForRowAt .

Я также могу подтвердить, что мои массивы заполняются и что проверка XCTAssertEqual прошла успешно.

Может ли кто-нибудь идентифицировать ошибку и объяснить, почему она возникла? Спасибо вам большое!

DataSource

class MovieDataService: NSObject {
    
    var movieManger: MovieManager?
}

extension MovieDataService: UITableViewDataSource {

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let librarySection = MovieLibrarySection(rawValue: indexPath.section) else { fatalError()}
        let (cellId, movieData) = getSectionCell(section: librarySection, index: indexPath.row)
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! MovieCell
        cell.configure(movieData)
        return cell
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        guard let movieManager = movieManger else {return 0}
        guard let librarySection = MovieLibrarySection(rawValue: section) else { fatalError()}
        return librarySection.rawValue == 0 ? movieManager.moviesToSee : movieManager.moviesSeen
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        guard let librarySection = MovieLibrarySection(rawValue: section) else { fatalError()}
        let sectionTitle = librarySection.rawValue == 0 ? "Movies To See" : "Movies Seen"
        
        return sectionTitle
    }
}

Unit Test

func testTableViewCell_SectionOneRowAtIndex_ReturnsToSeeMovieCell() {
        movieDataService.movieManger?.addMovie(actionMovie)
        tableView.reloadData()
        let queriedCell = tableView.cellForRow(at: IndexPath(row: 0, section: 0))
        
        XCTAssertEqual(tableView.numberOfRows(inSection: 0), 1)
        XCTAssertTrue(queriedCell is ToSeeMovieCell)
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...