我有一个困扰我的问题。我必须将iOS中的UI操作表中的信息存储到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 :(得分:0)
如果您是jsut尝试根据按钮索引选择字符串,请使用实例变量。例如,您可以在标头中声明NSString * yourString并按如下方式使用它:
if (button.index == 0) {
yourString = @"Mr."
}
只需遵循该模式即可,您可以从那里使用yourString做任何你想做的事。