遇到UITableViewCell问题

时间:2011-10-26 05:25:01

标签: iphone objective-c cocoa-touch uitableview

我正在使用新的iOS5 TableView样式代码,但我似乎遇到了问题。只要调用search = true函数,它就会崩溃。我认为将UITableView对象传递给configure方法并接受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;
    }
}

2 个答案:

答案 0 :(得分:2)

您将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:]。

尝试删除这些行。

答案 1 :(得分:0)

你需要从configure方法中删除这两行,因为如果前面三行暗示,你的'listOfItems'是一个字典列表,那么你试图将字典设置为textLabel的文本字段,会引起各种各样的问题。

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