2010-11-24 53 views
0
#import <UIKit/UIKit.h> 

typedef enum 
{ 
    CellTypeTextInput, 
    CellTypePicker 
}CellType; 

@interface TVCellWithProperties : UITableViewCell { 


    CellType _cellType; 
} 

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

@end 

页眉这里的值类型选择器有什么问题,objective-c?

#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的tableviewCell我是装是类型“的UITableViewCell”,所以我做到了“TVCellWithProperties”。 它工作。

谢谢NR4TR

回答

0

你确定要发送消息TVCellWithProperties实例,但不UITableViewCell实例?检查cellForRowAtIndexPath方法中的初始化。

+0

谢谢你的眼睛开放。 – LolaRun 2010-11-24 11:04:32

相关问题