通过另一个类将对象传递给一个类

用户名

我有一个tableview控制器类,一个tableviewcell子类和一个uibutton子类。我在tableviewcell子类中创建unbutton子类的实例,并在特定单元格位置初始化按钮。然后,我在tableview控制器类中使用此单元格。另外,我试图将IBAction添加到按钮。但是,在其他一切正常的情况下,它无法识别uibutton子类的对象。我在声明中做错了什么?

tableviewcell.m

#import "tableviewcell.h"
#import "CustomCheckButton.h"

    CustomCheckButton *starbtn = [[CustomCheckButton alloc] init];;


            starbtn = [[CustomCheckButton alloc]initWithFrame:CGRectMake(243,0, 30, 30)];

tableviewcontroller.m

在cellForRowAtIndexPath对象中,不会识别startbtn:

#import "ScannedProductControllerViewController.h"
#import "imageCellCell.h"


    tableviewcell*firstRowCell = (tableviewcell *)cell;


    [firstRowCell.prodimage  setImage: [UIImage imageNamed:@"test1.jpg"]];
    [firstRowCell.label1 setText:@"17.5"];
    [firstRowCell.label2 setText:@"Score"];

    [firstRowCell.basket  setImage: [UIImage imageNamed:@"Basket.jpg"]];

    // reference of the home button to the buttonclick method

    [firstRowCell.homebtn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];

    // reference of the favorites button to the buttonclick method

    [firstRowCell.starbtn addTarget:self action:@selector(clickFavButton:) forControlEvents:UIControlEventTouchUpInside];

CustomCheckButton.h

#import <UIKit/UIKit.h>

@interface CustomCheckButton : UIButton {
    BOOL    _checked;
}

@property (nonatomic, setter = setChecked:) BOOL checked;

-(void) setChecked:(BOOL) check;

@end
深红克里斯
@interface TableViewCell : UITableViewCell
@property (nonatomic, strong) CustomCheckButton *startButton;
@end

@implementation TableViewCell
- (instancetype)init {
    self = [super init];
    self.startButton = [[CustomCheckButton alloc]initWithFrame:CGRectMake(243,0, 30, 30)];
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.contentView addSubview:self.startButton];
}
@end

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Kivy/Python 如何将对象传递给另一个类?

将一个类的对象传递给另一个类的方法

SwiftUI通过引用将类对象传递给另一个视图

如何在我的 Java 代码中将对象传递给另一个类的方法?

将类的对象传递给另一个类

将另一个类的对象传递给单例类

将使用“ this”的类的对象传递给另一个类(Javascript)

将模板类的对象传递给另一个类的构造函数

将类对象传递给另一个类方法 Python

如何将编写的对象传递给另一个类的构造函数?

如何通过Java中的方法将对象从一个类传递到另一个类

将对象从一个类传递到另一个类

将对象数组传递给另一个类

将对象数组传递给另一个类

试图在反应时将对象传递给另一个页面

Flask 蓝图将对象传递给另一个文件

将对象传递给另一个活动(没有Parcelable?)

如何将对象传递给另一个模型的回调?

尝试将对象传递给同一个模板类进行复制

将类对象传递到另一个类中的列表的方法

如何将对象传递给方法然后传递给另一个方法

将模板化结构的对象传递给另一个模板化类的成员函数

如何将数组(firestore)中的选定对象传递给 react native 中的另一个类?

C ++将一个对象传递给另一个对象?

试图将一个对象的实例传递给另一个类

将对象传递给类并在同一个类中的静态函数中调用它

通过全局失败将连接对象传递到另一个类中(PHP)

angular 2 - 在 div 单击时,将对象传递给另一个组件,另一个组件使用该对象调用休息服务

jsp将对象传递给一个include