我使用this tutorial设置我的Parse应用的注册视图,我想使用additionalField
,除了我希望它是一个可选字段。 MySignUpViewController
检查以确保在提交之前填写所有字段的方式如下:
// Sent to the delegate to determine whether the sign up request should be submitted to the server.
- (BOOL)signUpViewController:(PFSignUpViewController *)signUpController shouldBeginSignUp:(NSDictionary *)info {
BOOL informationComplete = YES;
// loop through all of the submitted data
for (id key in info) {
NSString *field = [info objectForKey:key];
if (!field || !field.length) { // check completion
informationComplete = NO;
break;
}
}
// Display an alert if a field wasn't completed
if (!informationComplete) {
[[[UIAlertView alloc] initWithTitle:@"Missing Information" message:@"Make sure you fill out all of the information!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show];
}
return informationComplete;
}
这意味着它遍历所有字段并要求所有字段都包含其中的内容以进入下一步。如何在循环时告诉该循环忽略additionalField
?
答案 0 :(得分:1)
目标是使信息完成=是。为此,您可以执行以下操作:
// loop through all of the submitted data
for (id key in info) {
if (![key isEqualToString:@"KEYTOIGNORE"]) { //IF the key is not equal to specified string continue execution
NSString *field = [info objectForKey:key];
if (!field || !field.length) { // check completion
informationComplete = NO;
break;
}
}
}
这将阻止检查您要忽略的字段以查看它是否为空。所以要弄清楚它的关键是什么并试一试。让我知道它是怎么回事,祝你好运!