NSCFNumber rangeOfCharacterFromSet 错误解析

3

enter image description here 当我转到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."];
}
1个回答

10

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

希望这能帮到您。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接