NSCFNumber rangeOfCharacterFromSet 错误解析

NSCFNumber rangeOfCharacterFromSet Error Parse

转到 TabBarController 上的视图控制器时出现此错误:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0xb000000000000043'
*** First throw call stack:
(0x182a2422c 0x1946f00e4 0x182a2b2f4 0x182a280a8 0x18292a96c 0x187bf48c4 0x1874ddf68 0x10000ace8 0x10000a904 0x1874b7da8 0x18756f68c 0x180e30fb8 0x1874b7da8 0x1874b8314 0x1877e2d8c 0x1875240c0 0x187524028 0x1874944fc 0x1829dbff0 0x1829d8f7c 0x1829d935c 0x182904f74 0x18c35f6fc 0x187506d94 0x10000cb10 0x194d9aa08)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

我觉得它必须处理我的 yosTextField,它是一个数字(yos 代表服务年限)。文本字段被植入滚动视图内,以便文本字段在键盘上方向上滚动。代码:

#pragma mark - Backend actions

//-------------------------------------------------------------------------------------------------------------------------------------------------
- (void)loadUser
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
    PFUser *user = [PFUser currentUser];

    [imageUser setFile:user[PF_USER_PICTURE]];
    [imageUser loadInBackground];

    backgroundTextView.text = user[@"background"];
    companyTextField.text = user[@"company"];
    yosTextField.text = user[@"yos"];


    fieldName.text = user[PF_USER_FULLNAME];
    emailAddressTxtField.text = user[PF_USER_EMAIL];
}

//-------------------------------------------------------------------------------------------------------------------------------------------------
- (void)saveUser
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
    NSLog(@"save touched");
    NSString *fullname = fieldName.text;
    NSString *email = emailAddressTxtField.text;
    NSString *background = backgroundTextView.text;
    NSNumber *YOS = [NSNumber numberWithInt:[[yosTextField text] intValue]];
    NSString *company = companyTextField.text;
    if (([fullname length] != 0) || ([email length] != 0) || ([background length] != 0) || ([company length] != 0) || (YOS != 0))
    {
        PFUser *user = [PFUser currentUser];
        user[PF_USER_FULLNAME] = fullname;
        user[PF_USER_FULLNAME_LOWER] = [fullname lowercaseString];
        user[PF_USER_EMAIL] = email;
        user[@"background"] = background;
        user[@"company"] = company;
        user[@"yos"] = YOS;

        [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
         {
             if (error == nil)
             {
                 [ProgressHUD showSuccess:@"Saved."];
             }
             else [ProgressHUD showError:@"Network error."];
         }];
    }
    else [ProgressHUD showError:@"Name field must be set."];
}

错误表示您正在对 NSNumber 使用 NSString 方法。 请检查您的数据是否为字符串。

希望对您有所帮助。