Как воспроизвести видео при нажатии на ячейку? - PullRequest
1 голос
/ 02 ноября 2010

Я хочу открыть видео, когда я касаюсь первой ячейки, и я хочу открыть другое видео, когда я касаюсь второй ячейки и т. Д.

Может кто-нибудь, пожалуйста, сообщите мне, как я должен делатьэтот?У меня есть этот код.

  - (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    return 3;//[array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = 
    [tableView dequeueReusableCellWithIdentifier:@"cell"];

    // create a cell
    if ( cell == nil)
    {
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleSubtitle
                reuseIdentifier:@"cell"];
    }

    //retrieve an image/ Zet een afbeelding naast de titel
    NSString *imagefile = [[NSBundle mainBundle]
                           pathForResource:@"cellimage" ofType:@"png"];
    UIImage *ui = [[UIImage alloc] initWithContentsOfFile:imagefile];
    //set the image on the table cell/ zet hem in de tabel
    cell.imageView.image = ui;


    //set the main text/hoofd tekst
    cell.textLabel.text = [exercises objectAtIndex:indexPath.row];

    //set the subtitle text/ ondertekst
    cell.detailTextLabel.text = @"Management training", @"Ondertiteling hier", @"Ondertiteling hier";



    //accessory type /zijn de navigatie pijltjes, er zijn 3 verschillende 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    //return the cell
    //cell.textLabel.text = [array objectAtIndex:indexPath.row];
    return cell;
}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    exercises = [[NSArray alloc]
                 initWithObjects:@"BAZO", @"Ontslag gesprek",
                 @"Management training",nil];

    self.title = @"Training lijst";

    //Probeerzel
    /*array = [[NSMutableArray alloc] init];
    [array addObject:@"Bazo"];
    [array addObject:@"secondmovie"];*/


    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

Я знаю, что много кода, но это код таблицы.

Я уже импортировал MediaPlayer.framework.но я не знаю, как связать ячейку с видео.

Спасибо за ваше время!

Брэм

1 Ответ

2 голосов
/ 06 ноября 2010

Вам также потребуется установить контроллер представления в качестве делегата вашего табличного представления и реализовать метод делегата - [UITableViewDelegate tableView: didSelectRowAtIndexPath:] в контроллере представления. Это будет вызвано, когда пользователь коснется одной из ваших ячеек таблицы.

В вашей реализации tableView: didSelectRowAtIndexPath :, вы настроите MPMoviePlayerController для воспроизведения вашего фильма, что-то вроде этого:

- (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:
    NSURL * movieURL = [_movieFileURLs objectAtIndex:indexPath.row];

    // Now set up the movie player controller and play the movie.
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
    [[player view] setFrame: [self.view bounds]];  // frame must match parent view
    [self.view addSubview: [player view]];
    [player play];
}

Возможно, вы также захотите проверить документацию по MPMoviePlayerController по адресу http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html%23//apple_ref/doc/uid/TP40006953

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...