这是一个老问题,但我希望有我的老问题回答得这么......对了,还有一个更简单的方法使用块:
首先,在你的UITableViewCell接口声明的公共方法:
@interface YourCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *button;
- (void)setDidTapButtonBlock:(void (^)(id sender))didTapButtonBlock;
@end
在UITableViewCell子类实现文件中声明一个具有复制属性的私有属性。
#import "YourCell.h"
@interface YourCell()
@property (copy, nonatomic) void (^buttonTappedBlock)(id sender);
@end
添加在靶和UIControl的动作在的UITableViewCell构造并实现选择方法
- (void)awakeFromNib {
[super awakeFromNib];
[self.button addTarget:self
action:@selector(didTapButton:)
forControlEvents:UIControlEventTouchUpInside];
}
- (void)didTapButton:(id)sender {
if (buttonTappedBlock) {
buttonTappedBlock(sender);
}
}
最后实现在的tableView所述块码:的cellForRowAtIndexPath:在控制器方法
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
YourCell *cell = (YourCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
[cell buttonTappedBlock:^(id sender) {
NSLog(@"%@", item[@"title"]);
}];
return cell;
}
有关块的更多信息,请参阅Working With Blocks
在哪里写这行[self.adminController performSelector:@selector(openCamera)]; ?? – Muju