我在定制的UITableViewCell中有两个按钮。
每次点击按钮都应该调用所需的segue。
我在这样的单元格上设置了一个委托:
CustomCell.h
@protocol CustomCellDelegate
-(void)seeQuestions;
-(void)seeLessons;
@end
@interface CustomCell : UITableViewCell
@property (weak, nonatomic) id <CustomCellDelegate> delegate;
- (IBAction)seeQuestions:(UIButton *)sender;
- (IBAction)seeLessons:(UIButton *)sender;
CustomCell.m
- (IBAction)seeQuestions:(UIButton *)sender {
[self.delegate seeQuestions];
}
- (IBAction)seeLessons:(UIButton *)sender {
[self.delegate seeLessons];
}
现在,在ViewController类中,我有我的UITableView,显示自定义单元格,我导入CustomCell.h文件,并连接代理
ViewController.h
#import "CustomrCell.h"
@interface ViewController : UIViewController <CustomCellDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
-(void)seeQuestions;
-(void)seeLessons;
@end
ViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
cell.delegate = self;
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.title.text = [NSString stringWithFormat:@"%@",_topicsArray[indexPath.row]];
return cell;
}
-(void)seeQuestions
{
[self performSegueWithIdentifier:@"seeQuestions" sender:self];
}
-(void)seeLessons
{
[self performSegueWithIdentifier:@"seeLessons" sender:self];
}
但是,当我点击按钮时,没有任何反应。我确信我错过了一些显而易见的事情,但经过几个小时盯着我的代码,我似乎无法弄清楚我做错了什么。 有什么建议吗?