gpt4 book ai didi

iphone - iOS : How to attach a multiple attachment file in one button using pickerview method?

转载 作者:行者123 更新时间:2023-11-29 04:51:30 29 4
gpt4 key购买 nike

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

这是我的示例代码。

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
{

}


}

最佳答案

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

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

您可以对所有 pickerView 使用一个 pickerView 委托(delegate)方法。要确定选择哪个 pickerView,您应该检索发件人。

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

示例代码。只需将 3 个不同的委托(delegate)绑定(bind)到 IB 中的 3 个 slider 即可:

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

关于iphone - iOS : How to attach a multiple attachment file in one button using pickerview method?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8755403/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com