gpt4 book ai didi

ios - [NSPlaceholderMutableString initWithString :]: nil argument exception coming after casting the UITextField

转载 作者:行者123 更新时间:2023-11-29 11:39:11 26 4
gpt4 key购买 nike

我有这样的代码。

else if ([controlIn isKindOfClass:UITextField.class]) {
UITextField *cast = (UITextField *)controlIn;
if (cast.inputView != NULL) {
cast.text = [self setResolvedValue:cast metrixUIViewControllerIn:metrixUIViewControllerIn valueIn:valueIn];
} else {
cast.text = valueIn;
}

但是在 if (cast.inputView != NULL) 这行我得到了一个异常

"[NSPlaceholderMutableString initWithString:]: nil argument"

我的 cast 不是零。但是出现此错误的原因是什么。请帮我。谢谢

更新

+ (NSString*) setResolvedValue:(UIView *)viewIn metrixUIViewControllerIn:(MetrixUIViewController *)metrixUIViewControllerIn valueIn:(NSString *)valueIn {
NSMutableString *resolvedValue = [NSMutableString stringWithString:valueIn];
if (![MetrixStringHelper isNullOrEmpty:valueIn] && [viewIn.inputView isKindOfClass:[UIPickerView class]]) {
MetrixColumnDef *columnDef = [MetrixControlAssistant getColumnDefAssociatedToPicker:metrixUIViewControllerIn picker:(UIPickerView *)viewIn.inputView];
NSString *uniqueName = [MetrixControlAssistant getUniqueNameAssociatedToPicker:metrixUIViewControllerIn picker:(UIPickerView *)viewIn.inputView];
NSMutableArray *dataSet = [metrixUIViewControllerIn.pickerData objectForKey:uniqueName];
for (NSDictionary *dictionary in dataSet) {
if ([MetrixStringHelper value:valueIn isEqualTo:[dictionary objectForKey:columnDef.lookupDef.valueColumn]]) {
resolvedValue = [dictionary objectForKey:columnDef.lookupDef.displayColumn];
break;
}
}
}
return resolvedValue;

最佳答案

问题是因为当您初始化resolvedValuevalueIn 为nil。在使用它初始化 resolvedValue 之前检查并确保 valueIn 不为 nil。

您应该查看 Apple 文档 stringWithString:方法。

Raises an NSInvalidArgumentException if aString is nil.

尝试用下面的代码替换你的方法

+ (NSString*) setResolvedValue:(UIView *)viewIn metrixUIViewControllerIn:(MetrixUIViewController *)metrixUIViewControllerIn valueIn:(NSString *)valueIn {
if ([MetrixStringHelper isNullOrEmpty:valueIn] || ![viewIn.inputView isKindOfClass:[UIPickerView class]]) {
return @"";
}

NSMutableString *resolvedValue = [NSMutableString stringWithString:valueIn];
MetrixColumnDef *columnDef = [MetrixControlAssistant getColumnDefAssociatedToPicker:metrixUIViewControllerIn picker:(UIPickerView *)viewIn.inputView];
NSString *uniqueName = [MetrixControlAssistant getUniqueNameAssociatedToPicker:metrixUIViewControllerIn picker:(UIPickerView *)viewIn.inputView];
NSMutableArray *dataSet = [metrixUIViewControllerIn.pickerData objectForKey:uniqueName];
for (NSDictionary *dictionary in dataSet) {
if ([MetrixStringHelper value:valueIn isEqualTo:[dictionary objectForKey:columnDef.lookupDef.valueColumn]]) {
resolvedValue = [dictionary objectForKey:columnDef.lookupDef.displayColumn];
break;
}
}
return resolvedValue;
}

关于ios - [NSPlaceholderMutableString initWithString :]: nil argument exception coming after casting the UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47544702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com