首页 > 解决方案 > 如何使 UITableViewCell 笔尖配件工作?

问题描述

我想在我的自定义 UITableViewCell 上使用一个附件,但不幸的是我不知道该怎么做。我尝试制作一个插座,但线路没有连接到任何地方(尽管单元格选择了自定义类)。

这是笔尖的标题:

#import "UIKit/UIKit.h"

@interface CustomCreditCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *profileName;
@property (weak, nonatomic) IBOutlet UILabel *ccNumber;


@end

这是细胞类:

#import "CustomCreditCell.h"

@interface CustomCreditCell()
@end

@implementation CustomCreditCell



@end

标签: iosobjective-cxcode

解决方案


在您的头文件中,您通常会放置一个插座来引用您拖动到单元格的 IB 视图层次结构中的按钮。然后,您可以从 IB 中的单元类 ctrl 拖动到按钮上以连接插座。

@property (nonatomic, weak) IBOutlet UIButton *infoButton;

您还可以在单​​元类中创建一个操作,以便在单击按钮时接收消息:

- (IBAction) handleInfoButtonClick: (id) sender {
    /* do click here */
}

并 ctrl 从按钮拖动到 IB 中的单元格以指示按钮将调用什么操作。

对于将代码连接到界面元素的初学者教程,您可以参考 Apple 的入门教程:

https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ConnectTheUIToCode.html


推荐阅读