- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger numberOfRows = 0;
if (self.tableView == tableView)
{
numberOfRows = self.allMovies.count;
NSLog(@"NRA:%d", self.allMovies.count);
}
else
{
[self filterPlayers];
numberOfRows = self.filteredMovies.count;
NSLog(@"NRF:%d", self.filteredMovies.count);
}
return numberOfRows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SearchAndAddMovieCell";
FFFSearchAndAddMovieCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSLog(@"Cell is nil");
cell = [[FFFSearchAndAddMovieCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if (cell == nil)
NSLog(@"Still NIL");
}
Movie *movie;
if (self.tableView == tableView)
{
Movie *normalMovie = (Movie *)[self.allMovies objectAtIndex:indexPath.row];
movie = normalMovie;
NSLog(@"normal:%@", movie);
}
else
{
Movie *filteredMovie = [self.filteredMovies objectAtIndex:indexPath.row];
movie = filteredMovie;
NSLog(@"filter:%@", movie);
}
NSLog(@"1:%@|%@", movie.name, cell.movieName.text);
cell.movieName.text = movie.name;
NSLog(@"2:%@|%@", movie.name, cell.movieName.text);
cell.genre.text = movie.genre;
이렇게하면 내 초기 영화 목록이 완벽하게 채워집니다. 그러나, 내 UITableViewController에 대한 UISearchBar에 문자를 입력 할 때 NSLog에 결과가 표시되지만 결과가 나타나지 않습니다. 어떤 아이디어? 여기 왜 내 custom UITableViewCell이 cellForRowAtIndexPath에서 null입니까?
는2014-02-24 17:15:24.274 FantasyFeed[2367:60b] NRF:1
2014-02-24 17:15:24.278 FantasyFeed[2367:60b] Cell is nil
2014-02-24 17:15:24.281 FantasyFeed[2367:60b] filter:The Godfather
2014-02-24 17:15:24.283 FantasyFeed[2367:60b] 1:The Godfather|(null)
2014-02-24 17:15:24.286 FantasyFeed[2367:60b] 2:The Godfather|(null)
왜 cell.movieName.text 여기에 지속적으로 널 ... 로그 출력입니까? 내가 검색 창에 아무 것도 입력하기 전에, LOG는이 내가 굵은 글씨에 대한 궁금 것들입니다
2014-02-24 17:15:22.015 FantasyFeed[2367:60b] NRA:12
2014-02-24 17:15:22.021 FantasyFeed[2367:60b] normal:The Godfather
2014-02-24 17:15:22.023 FantasyFeed[2367:60b] 1:The Godfather|Label
2014-02-24 17:15:22.024 FantasyFeed[2367:60b] 2:The Godfather|The Godfather
... 다음과 같습니다. 정상적인 실행은 아래 2와 같지만 searchBar 실행은 정상 2와 같습니다.
2014-02-24 17 : 15 : 24.283 FantasyFeed [2367 : 60b] 1 : 대부 | (null)
2014-02-24 17 : 15 : 24.286 FantasyFeed [2367 : 60b] 2 : 대부 | (null)
2014-02-24 17 : 15 : 22.023 FantasyFeed [2367 : 60b] 1 : 대부 | 레이블
2014-02-24 17 : 15 : 22.024 FantasyFeed [2367 : 60b] 2 : 대부 | 대부
흠. 나는 UITableViewController있다. 스토리 보드에서 Identifier는 SearchAndAddMovieCell입니다. 내가 검색 창과 검색 디스플레이 컨트롤러를 가지고 있다는 것 이상. 나는 그것이 자신의 tableView를 가지고 있다고 생각하지만 ... Storyboard에 식별자를 추가 할 장소가없는 것 같습니다. 있어야할까요? 그게 내가 잃어버린거야? –
변경됨 FFFSearchAndAddMovieCell * cell = [tableView dequeueReusableCellWithIdentifier : CellIdentifier]; ~ FFFSearchAndAddMovieCell * cell = [self.tableView dequeueReusableCellWithIdentifier : CellIdentifier]; 이제 작동합니다. 결과 테이블이 self.tableView의 원본 전체 테이블보다 더 많은 셀을 가지지 않으므로이 문제가 해결된다고 가정합니다. –