【发布时间】:2014-05-26 22:04:49
【问题描述】:
我正在尝试在UITableViewCell 上添加视频,视频添加得非常完美,但问题是当我添加第二个视频时,UITableViewCell 上的第一个单元格变黑,第二个单元格显示视频。
我希望我的所有单元格都显示视频第一帧(视频图片)
但它只显示最后一个(最后一个单元格)
然后我添加UIButton 来播放它正常工作的每个单元格视频。
我的问题是我希望我的所有单元格在每个UITableViewCell 上都显示视频第一帧(视频图片)。
但问题是如果只添加一个单元格,那么它会完美地显示视频第一张图片。然后我点击按钮,它的启动视频完美,但是当我添加第二个视频时,第一个视频变黑,第二个视频完美运行。
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section==0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"listData"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil] autorelease];
cell.selectedBackgroundView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@".png"] ];
cell.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@".png"] ];
[cell setBackgroundColor:[UIColor clearColor]];
UILabel * lbl =[[UILabel alloc]initWithFrame:CGRectMake(330, 80, 135, 41)];
lbl.backgroundColor = [UIColor clearColor];
lbl.text = @"Play Video Here";
[cell.contentView addSubview:lbl];
NSInteger x = [[NSUserDefaults standardUserDefaults] integerForKey:@"cellRowNumber"];
NSLog(@"x is %d",x);
if (x<1) {
x = 0;
}
NSURL* url = [UIAppDelegate.videoUrlsArray objectAtIndex:indexPath.row];
NSLog(@"selected tableview row is %d",indexPath.row);
NSInteger p = indexPath.row ;
NSLog(@"P is %d",p);
secView2 =[[UIView alloc]initWithFrame:CGRectMake(84,5,600,170)];
secView2.tag = indexPath.row;
secView2.backgroundColor = [UIColor redColor];
[cell.contentView addSubview:secView2];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = CGRectMake(0,0,600,170);
moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
[moviePlayer prepareToPlay];
moviePlayer.shouldAutoplay = NO;
[secView2 addSubview:moviePlayer.view];
playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
playBtn.tag = indexPath.row;
playBtn.frame = CGRectMake(0,0,600,170);
[playBtn setBackgroundColor:[UIColor clearColor]];
playBtn.tag = indexPath.row;
[playBtn addTarget:self action:@selector(didButtonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
[secView2 addSubview:playBtn];
}
// moviePlayer.contentURL = [UIAppDelegate.videoUrlsArray objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//[self.moviePlayer pause];
return cell;
}
else {
// Nothing
}
//cell.textLabel.text = [UIAppDelegate.youTubeUrlsArray objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}
-(void)didButtonTouchUpInside:(id)sender{
UIButton *btn = (UIButton *) sender;
CGRect buttonFrameInTableView = [btn convertRect:btn.bounds toView:table];
NSIndexPath *indexPath = [table indexPathForRowAtPoint:buttonFrameInTableView.origin];
NSLog(@"%d",indexPath.row);
secView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 960)];
secView.backgroundColor = [UIColor redColor];
[self.view addSubview:secView];
NSURL* url = [UIAppDelegate.videoUrlsArray objectAtIndex:indexPath.row];
// Now set up the movie player controller and play the movie.
player = [[MPMoviePlayerController alloc] initWithContentURL: url];
[[player view] setFrame: CGRectMake(0, 50, 768, 910)]; // frame must match parent view
[secView addSubview: [player view]];
[player play];
//btn_hideSecview = [UIButton buttonWithType:UIButtonTypeCustom];
btn_hideSecview =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 45)];
btn_hideSecview.backgroundColor = [UIColor greenColor];
// btn_hideSecview.frame = CGRectMake(600, 0, 70, 45);
[btn_hideSecview setBackgroundColor:[UIColor whiteColor]];
[btn_hideSecview addTarget:self action:@selector(method_Hide_Secview) forControlEvents:UIControlEventTouchUpInside];
[secView addSubview:btn_hideSecview];
}
非常欢迎任何想法或建议。
【问题讨论】:
标签: ios iphone ipad uitableview