与错误代码在鸣叫正在播放的歌曲

问题描述:

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

} 

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

+0

它宣布为theSong',而不是歌曲。 – CodaFi 2012-01-15 18:34:04

它被宣布为'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]; 

}