【问题标题】:iOS : How to attach a multiple attachment file in one button using pickerview method?iOS:如何使用pickerview方法在一个按钮中附加多个附件文件?
【发布时间】:2012-01-06 08:52:51
【问题描述】:

我有一个要在选择器视图中附加的多个文件。当用户选择该选择器视图项目时,他们可以单击电子邮件按钮以附加所选文件。如何在我的选择器视图中执行此操作?

这是我的示例代码。

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:@"first@example.com"]; 
        NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
        NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

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

    }

电子邮件按钮:我如何从这里开始。

-(IBAction)showEmail
{

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

    }

    else
    {

    }


}

【问题讨论】:

    标签: iphone ios xcode ios4 uipickerview


    【解决方案1】:

    当用户在您的选择器视图中选择行时,您会将行标题保存到一些常用变量中 使用

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

    您可以为所有的pickerView 使用一种pickerView 委托方法。要确定选择了哪个pickerView,您应该检索发件人。

    然后在您的 showEmail 方法中,您只需使用保存的变量。

    示例代码。只需将 3 个不同的代表绑定到 IB 中的 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];
    }
    

    【讨论】:

    • 我在那里做了一些代码修改。我可能需要一个关于如何检索发件人的样本。我真的是初学者。我在代码修改中有一个名为 emailMe 的变量。
    • 你的意思是我需要两个pickerView委托方法:一个用于播放,一个用于电子邮件?
    • 当用户改变你的选择器视图的值时,你的类变量的值也会改变。然后,当用户按下按钮时,会调用 showEmail 并使用类变量的值。我更新了我的答案 - 为您添加了一些示例代码。这是一个视图上 3 个滑块的代码。每个滑块都有自己的委托。
    • 非常感谢。我会试验一下。
    猜你喜欢
    • 2015-11-29
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 2012-09-03
    相关资源
    最近更新 更多