2012-01-06 7 views
0

ピッカービュー内に複数のファイルを添付しています。ユーザーがそのピッカーの表示項目を選択すると、電子メールボタンをクリックして選択したファイルを添付できます。ピッカービューではどうすればいいですか?iOS:pickerviewメソッドを使用して1つのボタンに複数の添付ファイルを添付するにはどうすればよいですか?

ここは私のサンプルコードです。

Mファイル:

-(void)pickerViewEmail:(UIPickerView *)pickerViewEmail didSelectRow:(NSInteger)row inComponent:(NSInteger)component 

{ 


    if ([[musicList objectAtIndex:row] isEqual:@"m1"]) 
    { 

     MFMailComposeViewController *pickerEmail = [[MFMailComposeViewController alloc] init]; 
     pickerEmail.mailComposeDelegate = self; 

     NSString *path = [[NSBundle mainBundle] pathForResource:@"m1" ofType:@"mp3"]; 
     NSData *myData = [NSData dataWithContentsOfFile:path]; 
     [pickerEmail addAttachmentData:myData mimeType:@"audio/mp3" fileName:@"m1"]; 

     [pickerEmail setSubject:@"Hello!"]; 

     // Set up recipients 
     NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
     NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
     NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

     [pickerEmail setToRecipients:toRecipients]; 
     [pickerEmail setCcRecipients:ccRecipients]; 
     [pickerEmail setBccRecipients:bccRecipients]; 

     // Fill out the email body text 
     NSString *emailBody = @"Hello"; 
     [pickerEmail setMessageBody:emailBody isHTML:NO]; 

     [self presentModalViewController:pickerEmail animated:YES]; 
     [pickerEmail release]; 

    } 

メールボタン:どのように私はここからスタートします。ユーザーがpickerviewsの行を選択した場合

-(IBAction)showEmail 
{ 

    if ([MFMailComposeViewController canSendMail]) 
    { 
       [self pickerEmail]; I have a yellow error when i call this. What is the right solution? 

    } 

    else 
    { 

    } 


} 

答えて

1

は、あなたはいくつかの一般的な変数に行のタイトルを保存 あなたはすべてのあなたのpickerViewsための1つのpickerViewデリゲートメソッドを使用することができます

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 

を使用します。どのpickerViewが選択されているかを判断するには、送信者を取得する必要があります。

あなたのshowEmailメソッドでは、その保存された変数だけを使用します。

サンプルコード。 IBの3つのスライダに3人の異なる代理人をバインドするだけです:

-(IBAction)slider1Changed:(id)sender { 
    UISlider *slider = (UISlider *) sender; 
    int progressAsInt =(int)(slider.value + 0.5f); 
    NSString *newText =[[NSString alloc] 
         initWithFormat:@"%d",progressAsInt]; 
    label1.text = newText; 
    NSString *imgFileName = [NSString stringWithFormat:@"gold%i.png", progressAsInt]; 
    image1.image = [UIImage imageNamed:imgFileName]; 

    [newText release]; 
} 

-(IBAction)slider2Changed:(id)sender { 
    UISlider *slider = (UISlider *) sender; 
    int progressAsInt =(int)(slider.value + 0.5f); 
    NSString *newText =[[NSString alloc] 
         initWithFormat:@"%d",progressAsInt]; 
    label2.text = newText; 
    NSString *imgFileName = [NSString stringWithFormat:@"gold%i.png", progressAsInt]; 
    image2.image = [UIImage imageNamed:imgFileName]; 
    [newText release]; 
} 

-(IBAction)slider3Changed:(id)sender { 
    UISlider *slider = (UISlider *) sender; 
    int progressAsInt =(int)(slider.value + 0.5f); 
    NSString *newText =[[NSString alloc] 
         initWithFormat:@"%d",progressAsInt]; 
    label3.text = newText; 
    NSString *imgFileName = [NSString stringWithFormat:@"gold%i.png", progressAsInt]; 
    image3.image = [UIImage imageNamed:imgFileName]; 
    [newText release]; 
} 
+0

私はいくつかのコードの修正を行っています。私はおそらく送信者を取得する方法のサンプルが必要です。私は本当に初心者です。コード修正でemailMeという変数があります。 – Amink

+0

あなたは2つのpickerViewデリゲートメソッドが必要です:再生用とメール用のどちらですか? – Amink

+0

ユーザーがピッカービューの値を変更すると、クラス変数の値が変更されます。ユーザーがボタンを押すと、showEmailが呼び出され、クラス変数の値が使用されます。私は自分の答えを更新しました - いくつかのサンプルコードを追加しました。これは、1つのビューに3つのスライダがある場合のコードです。各スライダーには独自のデリゲートがあります。 – wzbozon

関連する問題