2014-02-21 2 views
1

Я пытаюсь добавить фильм в свою ячейку в свой UITableViewCell.View Not Adding to UITableViewCell

Фильм, похоже, играет со звуком, но без визуального. Я думаю, что мне сложно добавить вид filmPlayer в мою камеру.

Посмотрите на мой код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 


static NSString *CellIdentifier = @"FeedCustomCell"; 
FeedCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

// Configure the cell... 
cell.username.text = [NSString stringWithFormat:@"%@", _usernameString]; 
cell.createdDate.text = [NSString stringWithFormat:@"%@", _createdString]; 
return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// First, get the URL for the video file you want to play. For example, if you have an array of the movie file URLs, you'd do this: 

FeedCustomCell *cell = [[FeedCustomCell alloc] init]; 
NSURL *url = [NSURL URLWithString:_videoPathString]; 
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
moviePlayer.controlStyle = MPMovieControlStyleNone; 
CGRect previewFrame = CGRectMake(cell.videoView.frame.origin.x, cell.videoView.frame.origin.y, cell.videoView.frame.size.width, cell.videoView.frame.size.height); 
moviePlayer.view.frame = previewFrame; 
moviePlayer.repeatMode = MPMovieRepeatModeOne; 
[cell.videoView addSubview:moviePlayer.view]; 
[cell.videoView bringSubviewToFront:moviePlayer.view]; 
[moviePlayer play]; 

} 

Есть идеи?

+0

Im не уверен, но я думаю, вы должны добавить подвид затем воспроизводить видео не наоборот – meda

+0

ли cell.videoView для реально? Если он равен нулю или нет в границах просмотра содержимого ячейки, вы ничего не увидите. – matt

ответ

1

Вы на самом деле не создает MoviePlayer в вашей Tableview клетке. Внутри didSelectRowAtIndexPath метода вы создать еще один FeedCustomCell и добавить свой MoviePlayer там. Вы даже не добавляете это местное FeedCustomCell внутри ячейки таблицы.

Чем проще способ исправить это заменить

FeedCustomCell *cell = [[FeedCustomCell alloc] init]; 

с

FeedCustomCell *cell = (FeedCustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 
1

Вы выделение новой ячейки с этой линией:

FeedCustomCell *cell = [[FeedCustomCell alloc] init]; 

Но эта ячейка не существует нигде иерархии вида, поэтому он не будет отображаться. Если вы пытаетесь вставить видеопроигрыватель в существующую ячейку, которая прослушивается, то вы получите клетку, как это:

FeedCustomCell *cell = (FeedCustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 

В противном случае, если вы пытаетесь вставить новую ячейку, вам нужно сделайте следующее:

  1. Добавить новый товар в свою модель данных для представления новой ячейки.
  2. Вставьте новую строку, используя [tableView insertRowsAtIndexPaths:withRowAnimation:].
  3. Удалите и настройте вставленную ячейку в cellForRowAtIndexPath.
+0

Я получаю incopatible типы указателей для ячейки, когда я пытаюсь сделать строку cellForRowAtIndexPath. –

+0

@AnthonyGeranio: Попробуйте явно наложить на FeedCustomCell. Замените 'FeedCustomCell * cell = [tableView cellForRowAtIndexPath: indexPath];' с 'FeedCustomCell * cell = (FeedCustomCell *) [tableView cellForRowAtIndexPath: indexPath];' - Обратите внимание на дополнительный '(FeedCustomCell *)'. – GeneralMike

+0

@ AnthonyGeranio Извините, что я оставил актеры. Обновленный ответ. –

0

Когда вы

FeedCustomCell *cell = [[FeedCustomCell alloc] init]; 

в didSelectRowAtIndexPath, вы создаете целый новый экземпляр FeedCustomCell - то, что вы хотите сделать, это получить ячейку, щелкнул пользователь. Замените эту строку с:

FeedCustomCell *cell = (FeedCustomCell *)[tableView cellForRowAtIndexPath:indexPath];