Custom UITableViewCell delegate isn't calling a method

泄露秘密 提交于 2020-01-02 21:49:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!