0

シナリオは次のとおりです。

AVAudioPlayerを使用しています。

ポップオーバーとして表示されるUITableViewから曲を選択して再生しようとしています。

mp3アセットはマイドキュメントディレクトリにあります。

テーブルビューにデータを入力し、行を選択すると、その特定のアセットを再生できます。

私ができないことは、メインビューコントローラーにあるコントロールでポップオーバーが消えたら、オーディオを制御することです。(再生/停止/音量)

ポップオーバーをデリゲートにする@protocolがありますが、プロトコルに含まれるメソッドの構文を教えてくれる人はいますか?

@protocol SongChooserDelegate

-(void)didTap:(NSData *)データ; <------------ここで推測しています

@終わり

これが機能しない場合-何が機能しますか?

ありがとう、どんな助けでも大歓迎です....これは金曜日に予定されている私の卒業論文のための私のアプリを構築する私の最後のステップです!!!!! eeeek。

4

1 に答える 1

0

しばらく時間がかかりましたが、最終的にこれを理解しました。説明またはすべてのコードが必要な場合は、お知らせください。

//UITableViewController.h

@protocol SongChooserDelegate

-(void) didTap:(NSURL *)songUrl;

@終わり

//UITableView.m

  • (void)viewDidLoad { [self.player prepareToPlay];

    // ドキュメント ディレクトリを指す NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSError *エラー = nil; NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:パス エラー:&error]; if (array == nil) { // エラー処理 } self.songs = array;

    [super viewDidLoad];

}

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIAlertView *showSelection; NSString *メッセージ; message = [[NSString alloc] initWithFormat:@"%@", [songs objectAtIndex:indexPath.row]]; showSelection = [[UIAlertView alloc] initWithTitle:@"Track Selected" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [showSelection ショー]; [showSelection リリース]; [メッセージリリース];

    NSString *applicationDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSString *filePath = [applicationDocumentsDirectory stringByAppendingPathComponent: [songs objectAtIndex:indexPath.row]]; NSURL *url = [NSURL fileURLWithPath:filePath];

    [self.delegate didTap:url];

    }

//ViewController.h

@interface ViewController : UIViewController < SongChooserDelegate, AVAudioPlayerDelegate >

//ViewController.m

-(void) didTap:(NSURL *)songUrl{

 player = [[AVAudioPlayer alloc]initWithContentsOfURL:songUrl error:nil];

[プレーヤー prepareToPlay];

}

于 2011-05-05T12:47:23.407 に答える