Возникли проблемы с UITableViewCell - PullRequest
1 голос
/ 26 октября 2011

Я использую новый код стиля 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 ]

2 голосов
/ 26 октября 2011

Вы передаете словарь 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:].

попробуйте удалить эти строки.

0 голосов
/ 26 октября 2011

Вам нужно удалить эти две строки из вашего метода configure, потому что, если подразумевать предыдущие три строки, ваш 'listOfItems' является списком словарей, то вы пытаетесь установить словарь как текстовое поле textLabel, которое вызовет всевозможные проблемы.

cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...