简体   繁体   English

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSCFString nric]:

[英]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 ).实际错误将是您错误地将字符串放入数组中( copyListOfItemslistOfItems )。

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.

相关问题 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFString isDescendantOfView:]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString isDescendantOfView:]: 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[QBDDXMLElement attributeFloatValueForName:withDefaultValue:]: - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[QBDDXMLElement attributeFloatValueForName:withDefaultValue:]: 错误:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSCFNumber isEqualToString:]: - Error:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber isEqualToString:]: 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“-[NSDecimalNumber objectAtIndex:] - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSDecimalNumber objectAtIndex:] 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序, - Terminating app due to uncaught exception 'NSInvalidArgumentException', (由于未捕获的异常'NSInvalidArgumentException而终止应用程序) - (Terminating app due to uncaught exception 'NSInvalidArgumentException) 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException' 由于未捕获的异常'NSInvalidArgumentException而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序 - Terminating app due to uncaught exception 'NSInvalidArgumentException' 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“Receiver () 没有标识符为“pizzaSegue”的 segue - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'pizzaSegue'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM