I know this is simple, but iv tried and couldnt fix it. what am i missing?
I have an array of images placed in table view cells. once an image is clicked segue to new viewcontroller. the new view controller would then play the video that corresponds with the image.
I want to pass the selected image the next view and play the the right video. how do I pass vid1 or vid2 or vid3 to the next controller?
- (void)viewDidLoad
{
[super viewDidLoad];
Videos *vid1 = [Videos new];
vid1.name = @"name1";
vid1.detail = @"18:39 - 19:10";
vid1.imageFile = @"img1.png";
vid1.url = @"http://pv...mp4";
Videos *vid2 = [Videos new];
vid2.name = @"name2";
vid2.detail = @"6:51 - 7:10";
....
videos = [NSArray arrayWithObjects:vid1, vid2, vid3, nil];
}
// TABLE VIEW //
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"VideoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Videos * video = [videos objectAtIndex:indexPath.row];
UIImageView *videoImageView = (UIImageView *)[cell viewWithTag:100];
videoImageView.image = [UIImage imageNamed:video.imageFile];
return cell;
}
// SEGUE // - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showVideo"]) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:
[[sender superview] tag]];
playVideoViewController *destViewController = segue.destinationViewController;
// problem here
destViewController.video = [videos objectAtIndex:(long)indexPath.row];
NSLog(@"Segue to video page");
}
}
In my playVideoViewController:
-(void)showvideo {
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(mPMoviePlayerLoadStateDidChangeNotification) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[center addObserver:self selector:@selector(readytoplay) name:MPMoviePlayerReadyForDisplayDidChangeNotification object:nil];
NSURL* url = [NSURL URLWithString:
@"http://pv...mp4"];
//NSLog(@"url: %@", url);
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
}
How do I retrieve the correct the item from the array and play it?
Thanks for looking