gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:14:53 25 4
gpt4 key购买 nike

我想创建具有披露按钮的 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/

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