0

tableView で使用するカスタム TableView セルがあります。そのメソッドの一部を 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 に答える