2014-07-09 112 views
0

我将UIImageView添加到CustomCell(UITableViewCell的子类)。
但是,当我在CustomCell设置ImageView的图像,
应用程序冲突与日志消息:
[CustomCell setImageView:]:无法识别的选择器

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomCell setImageView:]: unrecognized selector sent to instance 0x10912d990' 

我有这样的代码。

的ViewController

@property (nonatomic, strong) UITableView* tableView; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 508)]; 
    self.tableView.delegate = self; 
    self.tableView.dataSource = self; 
    [self.view addSubview:self.tableView]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString* cellIdentifer = @"Cell"; 
    CustomCell* cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifer]; 
    if (cell == nil) { 
     cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer]; 
    } 
    switch (indexPath.section) { 
     case 0: 
      switch (indexPath.row) { 
       case 0: 
        cell.imageView.image = [UIImage imageNamed:@"hello.jpg"]; 
        break; 
       default: 
        break; 
      } 
     default: 
      break; 
    } 
    return cell; 
} 

CustomCell

@property (nonatomic, strong) UIImageView* imageView; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 310, 170)]; 
     [self addSubview:self.imageView]; 
    } 
    return self; 
} 

你有什么想法,将图像添加到ImageView的上customCell?
谢谢。

+1

穿上这条线调试点,看看它打它:' cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer]; ' – chuthan20

+0

使您的CustomCell成为支持setImageView方法的东西的子类。 –

+0

尝试在viewDidLoad中注册自定义单元格:self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@“CustomCell”]; –

回答

0

@property(nonatomic,strong)UIImageView * imageView;应该在CustomCell.h中而不是CustomCell.m中,以便可以从其他类访问。

0

谢谢了许多answers.I've解决。

@property (nonatomic, strong) UIImageView* imageView; 

@property (nonatomic, strong) UIImageView* myImageView; 
0

我认为你必须做喜欢的事,这... 在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     if (tableView==TABLE_MEMBERS)// && (count_cell%2==0)) 
     { 

      Groupie_Moment_Timeline_Cell_Members *cell_mem =[tableView dequeueReusableCellWithIdentifier:@"Groupie_Moment_Timeline_Cell_Members"]; 

      if (cell_mem==nil) 

      { 
       NSArray *nibs=[[NSBundle mainBundle] loadNibNamed:@"Groupie_Moment_Timeline_Cell_Members" owner:self options:nil 

    ]; 
       cell_mem=[nibs objectAtIndex:0]; 
      } 




    cell_mem.selectionStyle=UITableViewCellSelectionStyleNone; 
     [cell_small.IMG_TableImage setImage:[UIImage imageNamed:@"a.png"]; 
       return cell_small; 
相关问题