что не так с селектором для значения типа здесь, target-c? - PullRequest
0 голосов
/ 24 ноября 2010
#import <UIKit/UIKit.h>

typedef enum
{
    CellTypeTextInput,
    CellTypePicker
}CellType;

@interface TVCellWithProperties : UITableViewCell {


    CellType _cellType;
}

-(void)setCellType:(CellType)newType;
-(CellType)CellType;

@end

Заголовок

#import "TVCellWithProperties.h"

@implementation TVCellWithProperties

-(void)setCellType:(CellType)newType
{
    _cellType = newType;
}

-(CellType)CellType
{
    return  _cellType;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc {
    [super dealloc];
}
@end

Я делаю

[cell setCellType:CellTypePicker];

Завершение приложения из-за необработанного исключения «NSInvalidArgumentException», причина: '- [UITableViewCell setCellType:]: нераспознанный селектор, отправленный экземпляру 0x5f66c30'

Сначала я попробовал средства доступа по умолчанию, используя синтез, но не сработал, поэтому я попытался сделать что-то вручную, и он все еще не может найти селектор. Потому что он не видит UITableViewCell как TVCellWithProperties. Что не так с моей реализацией?

Я делал следующее:

TVCellWithProperties *cell = (TVCellWithProperties*)[tv dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"EditableContent" owner:self options:nil];

        cell = tvCell;
        self.tvCell=nil;
    }

Проблема заключалась в том, что в nibfile таблица viewCell, которую я загружал, имела тип «UITableViewCell», поэтому я сделал его «TVCellWithProperties». и это сработало.

Спасибо, NR4TR

1 Ответ

0 голосов
/ 24 ноября 2010

Вы уверены, что отправляете сообщение экземпляру TVCellWithProperties, но не UITableViewCell? Проверьте инициализации внутри cellForRowAtIndexPath метода.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...