user594161
user594161

Reputation:

Having trouble with UITableViewCell

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

Upvotes: 1

Views: 554

Answers (2)

shannoga
shannoga

Reputation: 19869

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.

Upvotes: 2

gamozzii
gamozzii

Reputation: 3921

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

Upvotes: 0

Related Questions