Adding a delegate to a custom UITableViewCell (bad access error)

后端 未结 3 1317
离开以前
离开以前 2020-12-10 14:36

I\'m trying to add a custom delegate to a custom UITableViewCell of mine.

On this cell I have a button which need to fire a method in the ViewController where the UI

3条回答
  •  时光取名叫无心
    2020-12-10 15:05

    I have heard that synthesized accessors should not be used during init. Try to do all the setup code using the ivars directly:

    myButton = [[UIButton alloc] init];         
    myButton.backgroundColor = [UIColor clearColor];         
    myButton.frame = CGRectMake(5, 0, 10, 32);         myButton.titleLabel.adjustsFontSizeToFitWidth = YES;         
    [myButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];         
    [contentView addSubview:myButton];
    

    If you change your button creation to [UIButton buttonWithType:UIButtonTypeCustom]; as beryllium rightly suggests, then you will also need to retain it.

提交回复
热议问题