2012-03-01 63 views
0

我遇到了困擾我的問題。我必須將iOS中的UI Action Sheet中的信息存儲到CoreData中提供的數組中。麻煩的是,操作表的功能與用於存儲數據的功能不同。將UIActionSheet數據存儲到CoreData中的數組中

第一:這是用於存儲數據的相關代碼:

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

其次,這裏的行動表上的代碼和處理輸入:

- (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."; 
} 
} 

我覺得我做很多新手的錯誤,請原諒我。我一直在學習如何編碼整個週末,你們是我最好的朋友。我只是沒有看到網絡上的這個特殊問題。

在此先感謝您的幫助!

克里斯

回答

0

如果你僅僅指剛嘗試選擇基於按鈕指數字符串中使用的實例變量。例如,你可以在頭聲明的NSString * yourString和按如下方式使用它:

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

只是下面這個模式應該工作,你可以從那裏做任何你想要與yourString。

相關問題