gpt4 book ai didi

uitableview - 点击单元格时如何播放视频?

转载 作者:行者123 更新时间:2023-11-29 11:24:25 25 4
gpt4 key购买 nike

我想在点击第一个单元格时打开一个视频,我想在我点击第二个单元格时打开另一个视频,依此类推。

有人可以告诉我我该怎么做吗?我有这个代码。

  - (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。但我不知道如何将单元格链接到视频。

感谢您的宝贵时间!

布拉姆

最佳答案

您还需要将 View Controller 设置为 TableView 的委托(delegate),并在 View Controller 中实现 -[UITableViewDelegate tableView:didSelectRowAtIndexPath:] 委托(delegate)方法。当用户点击您的表格单元格之一时,将调用此方法。

在 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];
}

您可能还想在 http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html%23//apple_ref/doc/uid/TP40006953 查看有关 MPMoviePlayerController 的文档

关于uitableview - 点击单元格时如何播放视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4076851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com