-(void)getWord:(NSString*)upperCaseString :(NSString *)combinedString :(NSString *)wordIndex
{
NSURL *url = [NSURL URLWithString:@"http://quicklanguages.com/materiales/quicklanguages/audios/%@/%@-%@.mp3",@"upperCaseString", @"combinedString", @"wordIndex" ];
// [tweetSheet setInitialText:[NSString stringWithFormat:@"%@",
[[_items objectAtIndex:indexPath.row] objectForKey:@"redirect_url"]]];
NSData *data = [NSData dataWithContentsOfURL:url];
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:nil];
// Now we are assigning it in an instance variable thus ARC will not deallocate it.
[audioPlayer play];
}
我创建一个方法并传递三个参数,现在可以用这个URL设置这些参数.....
答案 0 :(得分:0)
正确的方法是:
NSString *urlString = [NSString stringWithFormat:@"http://bla.bla/bla/%@/%@-%@.mp3", @"upperCaseString", @"combinedString", @"wordIndex"];
NSURL *url = [NSURL URLWithString:urlString];
修改强>
最终代码如下所示:
-(void)getWord:(NSString*)upperCaseString :(NSString *)combinedString :(NSString *)wordIndex
{
NSString *urlString = [NSString stringWithFormat:@"http://quicklanguages.com/materiales/quicklanguages/audios/%@/%@-%@.mp3",@"upperCaseString", @"combinedString", @"wordIndex"];
NSURL *url = [NSURL URLWithString:urlString];
// [tweetSheet setInitialText:[NSString stringWithFormat:@"%@",
[[_items objectAtIndex:indexPath.row] objectForKey:@"redirect_url"]]];
NSData *data = [NSData dataWithContentsOfURL:url];
audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:nil];
// Now we are assigning it in an instance variable thus ARC will not deallocate it.
[audioPlayer play];
}