UITableViewCell 遇到问题

发布于 2024-12-12 03:13:54 字数 1813 浏览 0 评论 0原文

我正在使用新的 iOS5 TableView 样式代码,但我似乎遇到了问题。每当调用 Searching = true 函数时,它都会崩溃。我认为尝试将 UITableView 对象传递给接受 BadgedCell 的配置方法。有什么想法如何解决这个问题吗?

Crash says: 2011-10-25 22:21:04.973 Social[5719:707] -[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510

2011-10-25 22:21:04.975 Social[5719:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510'

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(searching)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchCell"];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;
    }
    else
    {
        TDBadgedCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BadgedCell"];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;   
    }
}

- (void)configureCell:(TDBadgedCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    if(searching)
    {
        NSDictionary *dictionary = (NSDictionary *)[listOfItems objectAtIndex:indexPath.row];
        [cell.textLabel setText:[dictionary objectForKey:@"exerciseName"]];
        [cell.detailTextLabel setText:[dictionary objectForKey:@"muscleName"]];
        cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];
    }
    else
    {
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
        cell.textLabel.text = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
}

I'm using the new iOS5 TableView style code, but I seem to get a problem. It crashes whenever the searching = true function is called. I think it is triyng to pass the UITableView Object to the configure method with accepts the BadgedCell. Any ideas how to fix this?

Crash says: 2011-10-25 22:21:04.973 Social[5719:707] -[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510

2011-10-25 22:21:04.975 Social[5719:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510'

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(searching)
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchCell"];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;
    }
    else
    {
        TDBadgedCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BadgedCell"];
        [self configureCell:cell atIndexPath:indexPath];
        return cell;   
    }
}

- (void)configureCell:(TDBadgedCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    if(searching)
    {
        NSDictionary *dictionary = (NSDictionary *)[listOfItems objectAtIndex:indexPath.row];
        [cell.textLabel setText:[dictionary objectForKey:@"exerciseName"]];
        [cell.detailTextLabel setText:[dictionary objectForKey:@"muscleName"]];
        cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
        cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];
    }
    else
    {
        cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
        cell.textLabel.text = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
}

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

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

发布评论

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

评论(2

疏忽 2024-12-19 03:13:54

您将 listOfItems 字典作为字符串传递到单元格:

如果您使用此:

      NSDictionary *dictionary = (NSDictionary *)[listOfItems objectAtIndex:indexPath.row];

我知道 listOfItems 包含许多字典。
因此,当您调用时:

    cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];

您基本上是在尝试将字典分配给单元格标签。这就是为什么 Xcode 告诉你 [__NSCFDictionary isEqualToString:]。

尝试删除这些行。

You are passing the listOfItems dictionary as a string to the cell:

If you used this:

      NSDictionary *dictionary = (NSDictionary *)[listOfItems objectAtIndex:indexPath.row];

I understand that listOfItems contains many dictionaries.
So when you call:

    cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];

You are basically trying to assign a dictionary to a cell label. thats why Xcode is telling you that [__NSCFDictionary isEqualToString:].

try to remove those lines.

初熏 2024-12-19 03:13:54

您需要从配置方法中删除这两行,因为如果如前面三行所暗示的那样,您的“listOfItems”是一个字典列表,那么您尝试将字典设置为 textLabel 的文本字段,这将导致所有各种各样的问题。

cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];

You need to remove these two lines from inside your configure method, because if as the preceding three lines imply, your 'listOfItems' is a list of dictionaries then you are trying to set a dictionary as the text field of a textLabel which will cause all sorts of problems.

cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文