Ios 从许多方法调用ViewDid来更新NSMutableDictionary数据项
我对Objective C相当陌生,我正试图使用Xcode5开发一个应用程序 我将字符串(由数字1-9或N/A组成)存储在Ios 从许多方法调用ViewDid来更新NSMutableDictionary数据项,ios,objective-c,ios7,Ios,Objective C,Ios7,我对Objective C相当陌生,我正试图使用Xcode5开发一个应用程序 我将字符串(由数字1-9或N/A组成)存储在NSMutableDictionary中 当用户进入“查看您输入的结果页面”时,我希望他们能够手动进入文本字段,删除当前的值,并在必要时重新键入新值。但是,我不知道如何将这些信息重新加载到系统中,以便新的值将传递到电子邮件客户端,该客户端基本上将结果发送到用户希望的任何电子邮件地址 当前,在输入UIView时,使用viewdide加载值,但我认为如果更新了textField1
NSMutableDictionary
中
当用户进入“查看您输入的结果页面”时,我希望他们能够手动进入文本字段,删除当前的值,并在必要时重新键入新值。但是,我不知道如何将这些信息重新加载到系统中,以便新的值将传递到电子邮件客户端,该客户端基本上将结果发送到用户希望的任何电子邮件地址
当前,在输入UIView
时,使用viewdide
加载值,但我认为如果更新了textField1
,我需要再次调用它
我对所有textField
的textField
(在此处插入正确的数字)都有更新的方法,在这些方法中,我想将新值存储到NSMutableDictionary
(我相信我已经可以做到)
问题是,我无法确定如何获取在输入ui视图
时加载的词典的当前版本进行更新,以便视图中的信息显示为电子邮件的更新
希望这是有道理的。
正如我所说,对目标C来说绝对是新的。
下面是查看显示方法
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:(BOOL)animated];
AppDelegate *app = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSMutableDictionary *results = [app results];
NSString *firstResult = [results valueForKey:@"first"];
NSString *secondResult = [results valueForKey:@"second"];
NSString *thirdResult = [results valueForKey:@"third"];
if ([firstResult isEqual: @"N/A"]) {
self.Result1.text = results[@"first"];
} else {
int firstResultInt = [firstResult intValue]; firstResultInt++;
[_Result1 setText:[NSString stringWithFormat:@"%i", firstResultInt]];
}
if ([secondResult isEqual: @"N/A"]) {
self.Result2.text = results[@"second"];
} else {
int secondResultInt = [secondResult intValue]; secondResultInt++;
[_Result2 setText:[NSString stringWithFormat:@"%i", secondResultInt]];
}
if ([thirdResult isEqual: @"N/A"]) {
self.Result3.text = results[@"third"];
} else {
int thirdResultInt = [thirdResult intValue]; thirdResultInt++;
[_Result3 setText:[NSString stringWithFormat:@"%i", thirdResultInt]];
}
self.diningResult.text = results[@"dining"];
self.basementResult.text = results[@"basement"];
self.atticResult.text = results[@"attic"];
self.carResult.text = results[@"car"];
self.hallwayResult.text = results[@"hallway"];
self.garageResult.text = results[@"garage"];
self.other1Result.text = results[@"other"];
self.other2Result.text = results[@"other1"];
self.other1Name.text = results[@"other1name"];
self.other2Name.text = results[@"other2name"];
NSMutableString * str = [NSMutableString new];
[str appendString:@"Bedroom: "];
if ([firstResult isEqual: @"N/A"]) {
[str appendString: firstResult];
} else {
int firstResultInt = [firstResult intValue]; firstResultInt++;
NSString *firstResultString = [NSString stringWithFormat:@"%d",firstResultInt];
[str appendString: firstResultString];
}
[str appendString:@"\n"];
[str appendString:@"Living Room: "];
if ([secondResult isEqual: @"N/A"]) {
[str appendString: secondResult];
} else {
int secondResultInt = [secondResult intValue]; secondResultInt++;
NSString *secondResultString = [NSString stringWithFormat:@"%d",secondResultInt];
[str appendString: secondResultString];
}
[str appendString:@"\n"];
[str appendString:@"Kitchen: "];
if ([thirdResult isEqual: @"N/A"]) {
[str appendString: thirdResult];
} else {
int thirdResultInt = [thirdResult intValue]; thirdResultInt++;
NSString *thirdResultString = [NSString stringWithFormat:@"%d",thirdResultInt];
[str appendString: thirdResultString];
}
[str appendString:@"\n"];
[str appendString:@"Dining:"];
[str appendString:self.diningResult.text];
[str appendString:@"\n"];
//Code goes on to do the same with all other fields. all strings led by "str" get transferred over to the email
self.emailString = [NSString stringWithString:str];
}
代码不应调用viewdide
,框架有责任在适当的时间调用viewdide
。相反,您应该创建一个单独的方法,例如updateEmailContents
和UpdateTextFields
。然后从viewdideappear
调用这些方法,从uitextfieldDendediting
协议的textfieldDendediting
方法调用updateEmailContents
。。您不必担心重新加载
,因为您使用的是指针,如果您只需执行[dic setObject:newValue-forKey:key],它们将直接用NSMutableDictionary
更新
但是您不应该调用ViewDidDisplay,它是一个UIViewController
生命周期
方法,应该自动调用,而应该将所有代码放在一个函数中,并在需要时调用..用户说真话。你不应该自己调用viewDidAppear。我如何从viewDidAppear调用这些方法?禁止从一个函数隐式声明另一个函数