由于您正在使用自定义单元格,我认为您需要处理选择操作,因为您正在触摸自定义单元格内的按钮而不是单元格本身,因此表视图委托方法不会被触发。最好在您的自定义单元格中添加一个委托方法,例如在您的自定义单元格中。
在您的CellTypeOne.h
文件中添加以下内容:
@protocol TouchDelegateForCell1 <NSObject> //this delegate is fired each time you clicked the cell
- (void)touchedTheCell:(UIButton *)button;
@end
@interface CellTypeOne : UITableViewCell
{
}
@property(nonatomic, assign)id<TouchDelegateForCell1> delegate;
- (IBAction)actionForFirstButton:(id)sender;
- (IBAction)actionForSecondButton:(id)sender;
- (IBAction)actionForThirdButton:(id)sender;
- (IBAction)actionForFourthButton:(id)sender;
在你的CellTypeOne.m
文件中
@synthesize delegate;
- (IBAction)actionForFirstButton:(UIButton *)sender
{
if([self.delegate respondsToSelector:@selector(touchedTheCell:)])
{
[self.delegate touchedTheCell:sender];
}
}
在你的ViewContainingMyTableView.h
中
@interface ViewContainingMyTableView : UIViewController <UITableViewDelegate, UITableViewDataSource ,TouchDelegateForCell1> //confirms to custom delegate like table delegates
{
UITableView *myTBV;
}
@property (retain, nonatomic) IBOutlet UITableView *myTBV;
@end
并且在ViewContainingMyTableView.m
文件中
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CellTypeOne *cell1 = [self.aTableView dequeueReusableCellWithIdentifier:@"cell"];
if(cell1 == nil)
{
cell1 = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.delegate = self;
}
- (void)touchedTheCell:(UIButton *)button
{
NSIndexPath *indexPath = [self.aTableView indexPathForCell:(UITableViewCell *)button.superview];
NSLog(@"%@",indexPath.description);
}
在您的情况下,这是针对单元格中第一个按钮的,为每个具有不同功能的按钮添加委托方法,重复以上过程以获取单元格中的其他按钮。
希望您能理解 :) 祝编码愉快