我有这样的代码。
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参数”
我的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;
}
答案 0 :(得分:1)
问题是因为初始化valueIn
时resolvedValue
为零。在使用valueIn
初始化resolvedValue
之前,请检查并确保+ (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;
}
不为零。
您应该查看Apple文档中的stringWithString:方法。
如果aString为nil,则引发NSInvalidArgumentException。
尝试使用以下代码替换您的方法
POST https://account.visualstudio.com/DefaultCollection/_apis/wit/wiql?api-version=1.0