2014-10-20 93 views
0

我使用this tutorial來設置我的Parse應用程序的註冊視圖,並且我想使用additionalField,但我希望它是一個可選字段。在提交之前所有的字段都填補了MySignUpViewController檢查,以確保該方法是像這樣:如何使PFSignupViewController中的一個字段爲可選

// 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

回答

1

目標是使informationComplete = YES。要做到這一點,你可以這樣做:

// 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; 
     } 
    } 
} 

這將阻止檢查您要忽略的字段,看看它是否爲空。所以只要弄清楚它的關鍵是什麼,然後放手一搏。讓我知道它是怎麼回事,祝你好運!

+1

使完全感覺和工作完美,謝謝!原來,關鍵是「額外的」,對於任何嘗試這樣做的人來說。 – Ghobs 2014-10-20 02:50:09

相關問題