what is wrong with the selector for a valuetype here, objective-c?
#import <UIKit/UIKit.h>
typedef enum
{
CellTypeTextInput,
CellTypePicker
}CellType;
@interface TVCellWithProperties : UITableViewCell {
CellType _cellType;
}
-(void)setCellType:(CellType)newType;
-(CellType)CellType;
@end
The Header
#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
I'm doing
[cell setCellType:CellTypePicker];
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell setCellType:]: unrecognized selector sent to instance 0x5f66c30'
I tried the default accessors first using synthesize, but didn't work so i tried doing things manually and it st开发者_如何学Pythonill can't find the selector. Because it's not seeing the UITableViewCell as TVCellWithProperties. What's wrong with my implementation ?
I was doing the following:
TVCellWithProperties *cell = (TVCellWithProperties*)[tv dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"EditableContent" owner:self options:nil];
cell = tvCell;
self.tvCell=nil;
}
The problem was that in the nibfile, the tableviewCell i was loading was of type 'UITableViewCell', so i made it 'TVCellWithProperties'. and it worked.
Thank you NR4TR
Are you sure that you are sending message to TVCellWithProperties instance but not UITableViewCell instance? Check initializations inside cellForRowAtIndexPath method.
加载中,请稍侯......
精彩评论