#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