2013-03-21 78 views
0

我有一個NSArray從XML數據加載視頻文件。當你按下一個數組項時,它會用一個應該加載NSString url的按鈕加載一個視圖。這是我正在使用的代碼。來自URL的不兼容指針MPMoviePlayer

-(IBAction)playMovie:(id)sender 
    { 
     RSSItem* item = (RSSItem*)self.description; 
     NSURL *movieUrl = [NSURL URLWithString: item]; 
     MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl]; 
     [self.view addSubview:moviePlayerController.view]; 
     moviePlayerController.fullscreen = YES; 
     [moviePlayerController play]; 
    } 

我收到警告「不兼容的指針類型發送'的RSSItem * _strong爲鍵入‘的NSString *’

我已經試過各種參數,我能想到的字符串轉換爲字符串並得到它的工作。請讓我知道,如果這個問題太具體的或基本的論壇。

謝謝!

+0

什麼是RSSItem? – 2013-03-21 02:59:33

回答

1

此:

RSSItem* item = (RSSItem*)self.description;

應該是這樣的:

NSString* item = self.description;

在你上面的一行代碼是令人費解和不安。你爲什麼試圖將description(這是一個NSString開頭)RSSItem

+0

修復了警告。我仍然無法傳遞網址,但我需要在我這樣做之前弄清楚我的項目正在進行中。我不擅長傳遞數據,並且使用RaptureXML來解析xml提要,所以我需要弄清楚如何提取單個數據字符串。謝謝您的幫助! – 2013-03-21 04:09:00

+0

請務必注意@rmaddy所說的話! – borrrden 2013-03-21 04:13:02

+0

我現在把它切換到加載不同的屬性(NSURL),現在我的NSLog對NSURL返回null。 'NSURL * item = self.link; MPMoviePlayerController * moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:item]; [self.view addSubview:moviePlayerController.view]; NSLog(@「url =%@」,item); moviePlayerController.fullscreen = YES; [moviePlayerController play];' 您是否在此處看到任何內容,或者該問題來自正在創建的實例? – 2013-03-21 04:34:22

1

NSURL URLWithString:方法需要NSString類型的參數,但您傳遞一些未已知的RSSItem對象。您需要通過NSString

爲什麼要將self.description轉換爲RSSItemdescription方法是從NSObject開始的標準方法。它返回NSString

如果您已將自己的description方法添加到班級中,您應該重新命名它。方法description已經有一個特定的目的。

如果您使用的是標準description方法,那麼這是一個不好的用法。除調試外,絕對不應該使用description方法。

+0

謝謝!這有助於我更好地理解解決方案背後的邏輯。 – 2013-03-21 04:09:53