使用链接到视频的单元格创建一个tableview

时间:2012-10-15 18:22:39

标签: ios xcode ios5 ios6

我想创建具有公开按钮的tableview单元格,按下该按钮会链接到本地​​视频但我遇到问题,当我点击显示按钮时屏幕变黑,我正在使用弧形。我怎么能这样做?

这是我的示例代码。我做错了什么

这是我的头文件

 #import <UIKit/UIKit.h>
  #import <MediaPlayer/MediaPlayer.h>

 @interface BIDVideosViewController : UIViewController

 <UITableViewDelegate, UITableViewDataSource>

 @property (nonatomic,strong) NSArray *tableList;

 @end

这是我的.m文件

 #import "BIDVideosViewController.h"

 @interface BIDVideosViewController ()
 {
 MPMoviePlayerController *moviePlayer;

 }

 @end

 @implementation BIDVideosViewController

 @synthesize tableList;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
 }
 return self;
 }

- (void)viewDidLoad
{
[super viewDidLoad];
UITableView *table = [[UITableView alloc]initWithFrame:self.view.bounds];
[table setDelegate:self];
[table setDataSource:self];
[self.view addSubview:table];
 NSArray *array = [[NSArray alloc] initWithObjects:@"Gangan",@"SwimGood", nil];
self.tableList = array;
 // Do any additional setup after loading the view.
}

 - (void)didReceiveMemoryWarning
 {
 [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.
 }

 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
  return [tableList count];
  }
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   {
 static NSString *DisclosureButtonIdentifier = @"DisclosurebutotonIdentifier";
  UITableViewCell *cell = [tableView       dequeueReusableCellWithIdentifier:DisclosureButtonIdentifier];
  if (cell == nil)
  {
   cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault       reuseIdentifier:DisclosureButtonIdentifier];
   }
  NSInteger row = [indexPath row];
   NSString *rowString = [tableList objectAtIndex:row];
  cell.textLabel.text = rowString;
  cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
  return cell;
  }

  -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:   (NSIndexPath *)indexPath
  {
  NSString *thePath = [[NSBundle mainBundle] pathForResource:@"Gangan" ofType:@"mp4"];
  NSLog(@"path is ...%@", thePath);
  NSURL *theurl = [NSURL fileURLWithPath:thePath];
  MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];
  [moviePlayer.view setFrame:CGRectMake(0, 0, 320, 460)];
  [self.view addSubview:moviePlayer.view];
  [moviePlayer prepareToPlay];
  [moviePlayer play]; 

}

2 个答案:

答案 0 :(得分:3)

您没有UITableView或所需的numberOfSectionsInTableView:tableView:numberOfRowsInSection:方法。

尝试添加

UITableView *table = [[UITableView alloc] initWithFrame:self.view.bounds];
[table setDelegate:self];
[table setDataSource:self];
[self.view addSubview:table];

viewDidLoad功能。

查看所需方法的delegatedata source文档(以及可用的方法)以正确实现UITableView。这样做很好,因为它可以为您处理所有事情(绘图和设置)。您所要做的就是为它提供值,并在加载数据时自动绘制它。

答案 1 :(得分:1)

你可以这样尝试

NSString *thePath=[[NSBundle mainBundle] pathForResource:@"animation" ofType:@"mov"];
NSLog(@" path is...%@",thePath);
NSURL *theurl=[NSURL fileURLWithPath:thePath];

MPMoviePlayerController * moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:theurl];

[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 460)];  
[self.view addSubview: moviePlayer.view];
//[moviePlayer setFullscreen:YES animated:NO];
[moviePlayer prepareToPlay];
[moviePlayer play];

它为我工作,也希望为你工作