我正在尝试将电影添加到UITableViewCell中的单元格中。
这部电影似乎在播放声音,但没有视觉效果。我认为在将moviePlayer视图添加到我的单元时遇到麻烦。
看一下我的代码:
- (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];
}
有任何想法吗?
您实际上没有在tableview单元中创建moviePlayer。在内部didSelectRowAtIndexPath
方法中,您将创建另一个FeedCustomCell并在其中添加moviePlayer。您甚至没有在表视图单元格中添加此本地FeedCustomCell。
修复它的更简单方法是替换
FeedCustomCell *cell = [[FeedCustomCell alloc] init];
与
FeedCustomCell *cell = (FeedCustomCell *)[tableView cellForRowAtIndexPath:indexPath];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句