问题
I have two buttons in my custom-made UITableViewCell.
Each button click should call the desired segue.
I setup a delegate on a cell like this:
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];
}
Now, in the ViewController class, where I have my UITableView, showing the custom cell, I import the CustomCell.h file, and connect delegates
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];
}
But, when the I click the buttons, nothing happens. I am sure Im missing out some realy obvious thing, but after couple of hours staring at my code, i cannot seem to figure out what am I doing wrong. Any suggestions ?
来源:https://stackoverflow.com/questions/25666440/custom-uitableviewcell-delegate-isnt-calling-a-method