Подтвердить что ты не робот

Ошибка dequeueReusableCellWithIdentifier в моем UITableView в iOS5

Я получаю эту ошибку в iOS 5

-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance 0xa217200

Однако я не вижу ошибок в iOS 6. Как я могу исправить эту проблему? Здесь мой код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"MyCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; /// SIGABRT error

    if (!cell)
    {
        cell = [[UITableViewCell alloc]
        initWithStyle: UITableViewCellStyleSubtitle
        reuseIdentifier: CellIdentifier];
    }

    return cell;
}
4b9b3361

Ответ 1

EDIT: этот метод недавно добавлен в iOS6 + SDK.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

Но в iOS 5 для создания экземпляра UITableViewCell мы обычно используем этот метод: -

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

В iOS 5 нет необходимости в дополнительном параметре, который вы использовали в iOS 6. (forIndexPath:).

Итак, измените свой метод. Он будет работать.

Ответ 2

Вот почему вы получаете ошибку. В соответствии с iOS 6.0 Documentation Set UITableView Reference Reference указывает, что dequeueReusableCellWithIdentifier: доступен в iOS 2.0 и более поздних версиях, а dequeueReusableCellWithIdentifier:forIndexPath: доступен в iOS 6.0 и более поздних версиях.