您的位置:首页 > 产品设计 > UI/UE

UItableViewCell中有button处理

2015-06-18 10:45 375 查看
1.UITableViewCell 中有button

采取的办法一般有:

A.将事件放在cell里面,用Delegate传到VC中

#import <UIKit/UIKit.h>
@class CustomCell;
#define kCellIDentifier @"customCell"
@protocol CustomBtnDelegate <NSObject>
- (void)buttonPressWithCell:(CustomCell *)cell;
@end
@interface CustomCell :
UITableViewCell
@property (weak,
nonatomic) id<CustomBtnDelegate>delegate;
- (void)loadData:(NSString *)title;

- (IBAction)buttonPress:(UIButton *)sender
{
if (self.delegate && [self.delegate
respondsToSelector:@selector(buttonPressWithCell:)]) {
[self.delegate
buttonPressWithCell:self];
}
}

B.将btn的事件通过Block传出去

cell.h中

@class CustomCell;
typedef void(^ButtonActionBlock)(CustomCell *cell);
- (void)loadData:(NSString *)title action:(ButtonActionBlock)actionBlock;
.m中

- (void)loadData:(NSString *)title action:(ButtonActionBlock)actionBlock
{
_action = actionBlock;
_titleLabel.text = title;
[_selectBtn
setTitle:title forState:UIControlStateNormal];
}

- (IBAction)buttonPress:(UIButton *)sender
{
_action(self);
}
C.将Btn事件直接拖到VC中

- (IBAction)btnPress:(UIButton *)sender forEvent:(UIEvent *)event
{

UITouch *touch = [[event
allTouches] anyObject];
CGPoint point = [touch
locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView
indexPathForRowAtPoint:point];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: