Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios [CustomCell setImageView:]:无法识别的选择器_Ios_Objective C_Uitableview_Uiimageview - Fatal编程技术网

Ios [CustomCell setImageView:]:无法识别的选择器

Ios [CustomCell setImageView:]:无法识别的选择器,ios,objective-c,uitableview,uiimageview,Ios,Objective C,Uitableview,Uiimageview,我将UIImageView添加到CustomCell(UITableViewCell的子类)。 但是,当我在CustomCell的imageView上设置图像时, 应用程序与日志消息冲突: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomCell setImageView:]: unrecognized selector sent to instance 0x1091

我将UIImageView添加到CustomCell(UITableViewCell的子类)。
但是,当我在CustomCell的imageView上设置图像时,
应用程序与日志消息冲突:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomCell setImageView:]: unrecognized selector sent to instance 0x10912d990'
我有这个密码

视图控制器

@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;
}
定制单元

@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;
}
您有没有想法将图像添加到customCell上的imageView中?

谢谢。

@property(非原子,强)UIImageView*imageView;应该在CustomCell.h而不是CustomCell.m中,这样就可以从其他类访问它了。

您试图做的是用这一行
self.imageView=[[UIImageView alloc]initWithFrame:cRectMake(0,0,310,170)]设置
UITableViewCell
的超类readonly
imageView
属性。你不能那样做


文档:

谢谢您的回答。我已经解决了

@property (nonatomic, strong) UIImageView* imageView;


我想你必须像这样做。。。 在


在这一行上放置一个调试点,看看它是否命中它:
cell=[[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]使您的CustomCell成为支持setImageView方法的某个对象的子类。尝试在viewDidLoad:self.tableView registerClass:[CustomCell类]forCellReuseIdentifier:@“CustomCell”];是
@property(非原子,强)UIImageView*imageView实际在
CustomCell.m
中?如果您希望它可以公开访问,它应该位于
CustomCell.h
中。
@property (nonatomic, strong) UIImageView* myImageView;
    - (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;