I’ve got an issue that’s been bothering me. I have to store information from a UI Action Sheet in iOS into an array provided in CoreData. Trouble is, the Action Sheet is in a different function than the one used to store the data.
First: Here’s the relevant code for storing the data:
(... 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];
Second, here’s the code for the Action Sheet and handling the input:
- (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.";
}
}
I feel like I’m making a lot of newbie mistakes, so please forgive me. I’ve been learning how to code all weekend and you guys have been my best friend for this stuff. I just haven’t seen this particular issue on the net.
Thanks in advance for your help!
Chris
If you are jsut trying to select a string based on the button index use an instance variable. For example you could declare NSString* yourString in the header and use it as follows:
if (button.index == 0) {
yourString = @"Mr."
}
Just following that pattern should work and you can do whatever you want with yourString from there.