2012-03-01 13 views
0

私には迷惑をかけている問題があります。 iOSのUIアクションシートからCoreDataで提供される配列に情報を格納する必要があります。問題は、アクションシートがデータの保存に使用されたものとは異なる機能にあることです。私が作ってるようCoreDataの配列にUIActionSheetデータを格納する

- (void)showSalutation:(id)sender 
{ 
UIActionSheet *popUp = [[UIActionSheet alloc] initWithTitle:@"Choose Salutation" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Cancel" otherButtonTitles:@"Mr.", @"Mrs.", @"Ms.", @"Dr.", nil]; 
popUp.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
[popUp showInView:self.view]; 
[popUp release]; 
} 

- (void)showSalutation:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
if (buttonIndex == 0) 
{ 
    Salutation.text = @"Mr."; 
} 
else if (buttonIndex == 1) 
{ 
    Salutation.text = @"Mrs."; 
} 
else if (buttonIndex == 2) 
{ 
    Salutation.text = @"Ms."; 
} 
else if (buttonIndex == 3) 
{ 
    Salutation.text = @"Dr."; 
} 
} 

私が感じる:

まず:ここでは、データ格納するための関連するコードです:

(... checking for all fields; working properly) 

} 
else 
{ 
    newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:context]; 
    [newContact setValue:Salutation.text forKey:@"Salutation"]; 
    [newContact setValue:FirstName.text forKey:@"FirstName"]; 
    [newContact setValue:LastName.text forKey:@"LastName"]; 
    [newContact setValue:CompanyName.text forKey:@"CompanyName"]; 
    [newContact setValue:EmailAddress.text forKey:@"EmailAddress"]; 
    [newContact setValue:PhoneNumber.text forKey:@"PhoneNumber"]; 
    newContact.Disinfector =[NSNumber numberWithBool:yesWasher]; 
    newContact.Sterilizer =[NSNumber numberWithBool:yesSterilizer]; 
    newContact.CoffeeMaker =[NSNumber numberWithBool:yesCoffeeMaker]; 

    Salutation.text = @""; 
    FirstName.text = @""; 
    LastName.text = @""; 
    CompanyName.text = @""; 
    EmailAddress.text = @""; 
    PhoneNumber.text = @""; 
    yesWasher = YES; 
    [WasherTog setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal]; 
    yesSterilizer = YES; 
    [SterilizerTog setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal]; 
    yesCoffeeMaker = YES; 
    [CoffeeMakerTog setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal]; 

第二には、ここでのアクションシートのコードだと、入力を処理します初心者の間違いがたくさんあるので、私を許してください。私はすべての週末をコードする方法を学んできました、そして、あなたたちはこのもののために私の親友でした。私はちょうどネット上でこの特定の問題を見ていない。

ご協力いただきありがとうございます。クリス

答えて

0

あなたはjsutインスタンス変数を使用し、ボタンのインデックスに基づいて、文字列を選択しようとしている場合。たとえば、あなたは、ヘッダーにNSStringの* yourStringを宣言し、次のようにそれを使用することができます。

if (button.index == 0) { yourString = @"Mr." }

はちょうどそのパターンは動作するはずですし、あなたがそこからyourStringであなたがやりたいことができます以下。

関連する問題