问题描述
我有一个要在选择器视图中附加的多个文件。当用户选择该选择器视图项时,他们可以单击电子邮件按钮以附加所选文件。我如何在我的选择器视图中这样做?
I have a multiple file to attach inside the picker view. When user select that picker view item, they can click email button to attach the chosen file. How do I do so in my picker 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:@"[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];
}
电子邮件按钮:我如何从这里开始。
Email Button: How do i start from here.
-(IBAction)showEmail
{
if ([MFMailComposeViewController canSendMail])
{
[self pickerEmail]; I have a yellow error when i call this. What is the right solution?
}
else
{
}
}
推荐答案
当用户在选择器视图中选择行时,可以将行标题保存到一些常见变量中
使用
When user selects rows in your pickerviews, you save row titles to some common variablesusing
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
您可以为所有pickerView使用一个pickerView委托方法。要确定选择了哪个pickerView,您应该检索发件人。
You can use one pickerView delegate method for all your pickerViews. To determine, which pickerView is selected you should retrieve sender.
然后在您的showEmail方法中,您只需使用保存的变量。
Then in your showEmail method you just use that saved variables.
示例代码。只需将3个不同的代表绑定到IB中的3个滑块:
Sample code. Just bind 3 different delegates to 3 sliders in IB:
-(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];
}
这篇关于iOS:如何使用pickerview方法在一个按钮中附加多个附件文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!