playing videos in UITableViewCell
ios
Solution
Never add a subview to the cell:
[cell addSubview:moviePlayer.view];
Add it only to the contentView:
[cell.contentView addSubview:moviePlayer.view];
The other big mistake you're making is that you're forgetting that this cell can be reused; as the user scrolls, the cell be used for a different row of the table. So it gets reused, and now the movie player view is still in it even though this is now the wrong row of the table. You need not only to add the movie player view to the right cell, you need to remove it from all the wrong cells (in the `else` part of your code).
Problem
I am trying to play videos in the cells itself instead of a fullscreen video display. I am using `MPMoviePlayerController` for this purpose. I have defined ``` MPMoviePlayerController *moviePlayer; ``` in the implementation section Then in `cellForRowAtIndexPath:` I do this ``` cell = [tableView dequeueReusableCellWithIdentifier:simpleTableVideoIdentifier]; if (cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableVideoIdentifier]; } NSDictionary *dictionary = [dataArray objectAtIndex:indexPath.section]; NSDictionary *data = dictionary; if ([data[@"type_of_post"] isEqualToString:@"video"]) { NSString *path = data[@"video"]; NSURL *videoURL = [NSURL URLWithString:path]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; [moviePlayer setControlStyle:MPMovieControlStyleNone]; moviePlayer.scalingMode = MPMovieScalingModeAspectFit; [moviePlayer.view setFrame:CGRectMake(10.0, 0.0, 300.0 , 400.0)]; [cell addSubview:moviePlayer.view]; moviePlayer.view.hidden = NO; [moviePlayer prepareToPlay]; [moviePlayer play]; }else{ //do something else } ``` and obviously I assign it a height in `heightForRowAtIndexPath:` but the point it as `MPMoviePlayerController *moviePlayer;` is defined globally it doesn't stick to just its cell but keeps on coming down as I scroll down. I am not sure what other way to implement this other than what I described, which clearly doesn't seem the right way to go about it. I would really appreciate if someone can guide me to the right direction. Thanks