ios - 使用链接到视频的单元格创建表格 View

标签 ios xcode ios5 ios6

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

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

这是我的头文件

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

}

最佳答案

您没有 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 所需方法(以及可用方法)的文档。这样做很好,因为它会为您处理一切(绘图和设置)。您所要做的就是给它赋值,它会在加载数据时自动绘制它。

关于ios - 使用链接到视频的单元格创建表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12901672/

相关文章:

ios - 如何在资源为 5mb 时减小巨大的 .ipa 文件大小

ios - xcodebuild 存档失败,xcode 存档成功

ios - 如何关闭 PushViewController?

iphone - 如何在 iOS5 的分段控件中自定义突出显示的文本颜色?

ios - 检查是否已在 Apple Watch 上授予 HealthKit 权限的最佳方法?

iphone - CoreData 查找字符串 - NSPredicate 或 for 循环?

ios - 如何在 xcode 中打开现有的本地 pod?

ios - 为什么 WatchKit 类在新的 .swift 文件中无法识别?

ios - UINavigationBar 自定义背景图片

ios - 在 iOS 中,带有属性文本的 textview 的高度有时是错误的