2012-10-15 71 views
0

我想創建具有泄漏按鈕的tableview單元格,當按下該按鈕時鏈接到本地​​視頻但我遇到問題,當我點擊揭示按鈕時,屏幕變黑,我正在使用弧。我該如何解決這個問題?用鏈接到視頻的單元格創建表格視圖

這裏是我的樣品code..What我做錯了

這裏是我的頭文件

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

}

+3

你沒有說明是什麼問題。還有** numberOfSectionsInTableView:**和** tableView:numberOfRowsInSection:**方法? – rmaddy

+0

感謝您指出,我插入'numberOfSectionsInTableView'方法,並添加了幾行'ViewDidLoad',雖然我得到的視頻和披露按鈕的字符串名稱,當我點擊它們沒有任何反應,任何想法,我可能有錯,請幫助..謝謝 – DanKiiing

+0

子類'UITableViewController'而不是'UIViewController'是不是更容易? – Abizern

回答

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的可用方法。它很適合這樣做,因爲它可以爲你處理所有事情(繪圖和設置)。你所要做的就是給它賦值,並且在加載數據時自動繪製它。

+0

..哇感謝您輸入的一百萬,這真的很有幫助我有兩個視頻的名稱,我想播放顯示在應用程序以及披露按鈕,但是,當我點擊它們什麼也沒有發生,我相信這只是一個小問題,無法弄清楚。我已更新我的代碼..請再次看看,讓我知道你的想法..謝謝 – DanKiiing

+0

你確定沒有任何反應?當我這樣做時,它工作得很好。即使NSLog沒有被輸出到控制檯? – RileyE

+0

嘿人@RileyE再次感謝您的意見,我有一個輕微的錯誤,MPMovieController被實施..我解決了問題:) – DanKiiing

1

你可以嘗試這樣的

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

的MPMoviePlayerController * moviePlayer = [[的MPMoviePlayerController頁頭] initWithContentURL:theurl]。

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

它爲我工作,希望爲你工作太

+0

謝謝隊友,我整理出來:) – DanKiiing

+0

我知道獻愛的原因嗎? – SAHIL

+0

不知道我做到了,我再次投了票,表示歉意 – DanKiiing

相關問題