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

发布于 2024-11-15 14:41:11 字数 1331 浏览 2 评论 0原文

当我使用刚刚实现的搜索栏时,我收到此错误。有些字母可以工作,而另一些字母则会因标题中的错误而崩溃。错误似乎就在这里,但我无法弄清楚它出了什么问题:“cell.textLabel.text = info.nric;”。

有人请帮忙=(

- (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;
}

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;".

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蒲公英的约定 2024-11-22 14:41:11

您认为只包含 PatientInfo 对象的数组之一实际上包含一个 NSString。因此,当您编写 info.nric 时,它会向 NSString 询问其 nric 属性,而该属性当然不存在。实际的错误将出现在您错误地将字符串放入数组的任何位置(copyListOfItemslistOfItems)。

One of the arrays that you think contains only PatientInfo objects actually contains an NSString. So when you then write info.nric, it's asking that NSString for its nric property, which of course doesn't exist. The actual error would be wherever you're mistakenly putting a string in the array (either copyListOfItems or listOfItems).

旧故 2024-11-22 14:41:11

替换成下面的代码,你就会知道你的代码到底出了什么问题:

PatientInfo *info = [copyListOfItems objectAtIndex:indexPath.row];
if((nil != info) && ([info isKindOfClass:[PatientInfo class]))
{
    if([info respondsToSelector:@selector(nric)])
    {
        cell.textLabel.text = info.nric;
    }
}

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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文