0

我想创建具有披露按钮的表格视图单元格,按下该按钮时将链接到本地​​视频,但我遇到问题,当我单击披露按钮时屏幕变黑,我正在使用弧。我该怎么办?

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

这是我的头文件

 #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]; 

}

4

2 回答 2

3

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

尝试添加

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

到你的viewDidLoad功能。

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

于 2012-10-15T19:23:04.450 回答
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];

它对我有用,希望对你也有用

于 2012-10-16T11:39:12.550 回答