smo*_*ter 5 uitableview ios xcode-storyboard
我在故事板中的原型单元格上有一个自定义附件视图(UIButton).单击该按钮时,不会调用轻触的附件按钮的委托方法.如果我使用标准的披露按钮,它被称为罚款.我假设我错过了某个地方.谁知道在哪里?
我最终使用自定义表格单元格协议解决了这个问题。
CustomAccessoryTableCellDelegate.h
@protocol CustomAccessoryTableCellDelegate <NSObject>
@required
- (void) accessoryButtonTappedForCell: (UITableViewCell *) cell;
@end
Run Code Online (Sandbox Code Playgroud)
CustomAccessoryViewTableCell.h
@interface CustomAccessoryViewTableCell : UITableViewCell
/** The custom accessory delegate. */
@property (nonatomic, weak) id<CustomAccessoryTableCellDelegate> delegate;
@end
Run Code Online (Sandbox Code Playgroud)
CustomAccessoryViewTableCell.m
- (IBAction) buttonAction:(id)sender{
if ([self.delegate respondsToSelector:@selector(accessoryButtonTappedForCell:)]) {
[self.delegate accessoryButtonTappedForCell:self];
}
}
Run Code Online (Sandbox Code Playgroud)
内部表视图控制器
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
CustomAccessoryViewTableCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"MyCustomCell"];
cell.label.text = @"Some Name";
cell.delegate = self;
return cell;
}
#pragma mark - Custom Accessory View Delegate
- (void) accessoryButtonTappedForCell:(UITableViewCell *)cell{
[self tableView:self.writerTable
accessoryButtonTappedForRowWithIndexPath: [self.writerTable
indexPathForCell:cell]];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4644 次 |
| 最近记录: |