0

我有一个在 tableView 中使用的自定义 TableView Cell - 我决定我需要将它的一些方法委托给 tableViewController。

//Custom tableview cell
typedef enum {
    kButtonSelected,
    kButtonNormal
} ButtonState;

// Classes using this custom cell must implement these methods
@protocol CustomTableViewCellDelegate <NSObject>
@required
- (void) storeButtonState:(ButtonState)state forButton:(UIButton *)sender;
- (void) restoreButtonState:(UIButton *)tagLectureButton;

@end

@interface CustomTableViewCell : UITableViewCell

// Delegate
@property (assign) id <CustomTableViewCellDelegate> delegate;

@property (weak, nonatomic) IBOutlet UILabel *mainLabel;
@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *spinner;
@property (weak, nonatomic) IBOutlet UIButton *tagLectureButton;

然后我将 TableView 设置为它的委托并实现方法。到目前为止,一切都很好

@interface LecturesSubTVC : LecturesTVC <CustomTableViewCellDelegate>

但我没有要设置的实例变量(self.CustomTableViewCell.delegate = self;)

所有单元格都在这样的方法中分配:

CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

如何将单元格设置为委托,以便调用委托的方法?

4

2 回答 2

2

你似乎已经准备好了一切。在将一个单元格出队后

CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

只需将其委托设置为cell.delegate = self;

于 2013-07-07T03:53:43.307 回答
1
CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.delegate = self;
于 2013-07-07T03:54:34.170 回答