[英]Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString nric]:
I get this error when i play with the searchbar that I have just implemented.. Some letters work while others will crash with the error in the title.当我使用刚刚实现的搜索栏时出现此错误。有些字母可以正常工作,而其他字母会因标题中的错误而崩溃。 The error seems to be here but i cannot figure out what is wrong with it: "cell.textLabel.text = info.nric;".错误似乎在这里,但我无法弄清楚它有什么问题:“cell.textLabel.text = info.nric;”。
Someone please help =(有人请帮忙=(
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if(searching){
PatientInfo *info = [copyListOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = info.nric;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age];
}
else {
//First get the dictionary object
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"Patients"];
PatientInfo *info = [array objectAtIndex:indexPath.row];
// NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = info.nric;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%i, %i", info.category, info.age];
}
return cell;
}
One of the arrays that you think contains only PatientInfo
objects actually contains an NSString.您认为仅包含PatientInfo
对象的 arrays 之一实际上包含一个 NSString。 So when you then write info.nric
, it's asking that NSString for its nric
property, which of course doesn't exist.因此,当您编写info.nric
时,它会询问 NSString 的nric
属性,这当然不存在。 The actual error would be wherever you're mistakenly putting a string in the array (either copyListOfItems
or listOfItems
).实际错误将是您错误地将字符串放入数组中( copyListOfItems
或listOfItems
)。
Replace with the following code, you will know what exactly is going wrong in your code:替换为以下代码,您将知道代码中到底出了什么问题:
PatientInfo *info = [copyListOfItems objectAtIndex:indexPath.row];
if((nil != info) && ([info isKindOfClass:[PatientInfo class]))
{
if([info respondsToSelector:@selector(nric)])
{
cell.textLabel.text = info.nric;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.