从 UIPickerView 检索行索引并在 if 语句中使用它 [英] Retrieving row index from UIPickerView and using it in a if statement

查看:17
本文介绍了从 UIPickerView 检索行索引并在 if 语句中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我说的不清楚,请再次原谅我,我昨天才开始 iOS 开发.

Again forgive me if im not being clear, I have only started iOS dev yesterday.

所以我有一个应用程序将信息发送到特定的电子邮件地址.我已经包含了一个选择器视图,并用一系列信息填充它,5 或 6 个不同的类别.我想要做的是能够根据选择器视图中选择的类别更改电子邮件的收件人.

So I have a application that is going to send information to specific email address. I have included a pickerview and populated it with an array of information, 5 or 6 different categories. What i want to do is to be able to change the recipient's of the email based on what category is selected in the pickerview.

到目前为止我有但 selectedRowInComponent 似乎不起作用.

So far I have but selectedRowInComponent doesn't seem to work.

- (IBAction)sendFinalItem:(UIButton *)sender {


NSLog(@"send button pressed");


if ([self.pickerView selectedRowInComponent:(0)])
{

    MFMailComposeViewController *mailcontroller = [[MFMailComposeViewController alloc] init];
    [mailcontroller setMailComposeDelegate:self]; 
    NSString *email =@"k_scully@hotmail.co.uk";

    NSArray *emailArray = [[NSArray alloc] initWithObjects:email, nil]; 
    [mailcontroller  setToRecipients:emailArray]; 
    [mailcontroller setSubject:@"[Urgent]Potential Job, iPhone snapped"];

    [self presentViewController:mailcontroller animated:YES completion:nil];
    [mailcontroller setMessageBody:notesTextView.text isHTML:NO];
}

推荐答案

selectedRowInComponent: 返回用户所做选择的索引.您可以使用该值来检查您需要使用哪个电子邮件地址.

selectedRowInComponent: returns the index of the selection made by the user. You can use that value to check which e-mail address you need to use.

NSInteger selectedRow  = [self.pickerView selectedRowInComponent:0];
if (selectedRow == 0)
{
    // E-mail person 1
}
else if (selectedRow == 1)
{
    // E-mail person 2
}
// etc.

这篇关于从 UIPickerView 检索行索引并在 if 语句中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆