2012-04-25 3 views
2

iOS 앱에서 YouTube 기능을 사용하려고합니다. 특정 사용자의 비디오 목록을 성공적으로 검색하고 있지만 선택한 비디오를 별도의 viewController에 포함 시키려면 didSelectRowAtIndexPath를 구현하는 데 어려움을 겪고 있습니다. 저는 여기에 문제가 있어요 코드입니다 :YouTube 동영상 GData API

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"]; 

    GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row]; 
    videoArray = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents]; 
    NSString *tempUrl = [videoArray objectAtIndex:0]; 
    NSLog(@"The URL is:%@",tempUrl); 
    detailController.videoString = tempUrl; 

    [self.navigationController pushViewController:detailController animated:YES]; 

} 

내가 이것을 실행할 때마다, 나는에서 중단 점을 얻을 'detailController.videoString = tempUrl을;'

The URL is:GDataMediaContent 0x69c76a0: {url:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata type:application/x-shockwave-flash medium:video isDefault:true expression:full duration:1913} 

가 어떻게이의 GData의 API에서 바로 동영상 URL을 추출 할 수 있습니다 : 나는 tempUrl 문자열이 NSLog를 통해 다음과 같이 채워지는 것을 볼 수 있어요

?

미리 답변 해 주셔서 감사합니다.

나는 다음과 같이 변경했고 지금은 적절한 URL 문자열을 얻고있다 :

GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row]; 
    NSArray *mediaContents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents]; 
    GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:mediaContents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"]; 
    NSLog(@"The URL is:%@",[flashContent URLString]); 
    detailController.videoString = [flashContent URLString]; 

NSLog에서 다음 나에게 제공합니다

The URL is:https://www.youtube.com/v/s36krFdPmYQ?version=3&f=user_uploads&app=youtube_gdata 

내가 그러나 아직도에서 중단 점을 얻고을 ' detailController.videoString = [flashContent URLString];

답변

3

이 문제를 해결할 수있었습니다. 두 ViewController 사이에 모달 (modal) 구획을 추가하고 내 코드를 약간 수정했습니다. https://gist.github.com/2501684

:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"]; 
    GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row]; 
    NSString *title = [[entry2 title] stringValue]; 
    NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents]; 
    GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:contents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"]; 
    NSString *tempURL = [flashContent URLString]; 

    detailController.videoString = tempURL; 
    detailController.titleString = title; 
    [self.navigationController pushViewController:detailController animated:YES]; 

} 

당신은 여기에 전체 작업 YouTubeDemo 응용 프로그램 코드를 볼 수 있습니다 : 여기가 SEGUE를 추가 한 후 사용하여 종료 코드입니다