使用代码获取和发布正在播放的歌曲的错误

时间:2012-01-15 17:52:24

标签: iphone ios xcode twitter

The errors

- (IBAction)playingSong {
MPMediaItem *theSong = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
NSString *theTitle   = [song valueForProperty:MPMediaItemPropertyTitle];
NSString *theArtist  = [song valueForProperty:MPMediaItemPropertyArtist];
NSString *nowPlaying = [NSString stringWithFormat:@"#NowPlaying %@ by %@", theTitle, theArtist];
tweetTextView.text = [NSString stringWithFormat:@"%@%@", nowPlaying, tweetTextView.text];
[self setChars];
}

- (IBAction)sendMusicTweet:(id)sender {
    TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
    [tweetViewController setInitialText:tweetTextView.text];
    [self presentModalViewController:tweetViewController animated:YES];

}

我已经导入了框架。但我不知道如何解决这个错误......我该怎么办?谢谢:))

1 个答案:

答案 0 :(得分:0)

它被宣称为'theSong',而不是歌曲。您从未在.h中声明指向tweetTextView的指针,并且未在任何文件中定义setChars。

您的代码应该是:

- (IBAction)playingSong {
MPMediaItem *theSong = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem];
NSString *theTitle   = [theSong valueForProperty:MPMediaItemPropertyTitle];
NSString *theArtist  = [theSong valueForProperty:MPMediaItemPropertyArtist];
NSString *nowPlaying = [NSString stringWithFormat:@"#NowPlaying %@ by %@", theTitle, theArtist];
//Declare tweetTextView in the .h!!
tweetTextView.text = [NSString stringWithFormat:@"%@%@", nowPlaying, tweetTextView.text];
//[self setChars]; Define this In the .h!
}

- (IBAction)sendMusicTweet:(id)sender {
    TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
    [tweetViewController setInitialText:tweetTextView.text];
    [self presentModalViewController:tweetViewController animated:YES];

}