찾다

 >  Q&A  >  본문

ios - 继承UIView的类里创建一个tableView,然而对应的tableFooterView不能响应事件是为什么?

我继承了UIView的类里创建了一个tableView,当我在这个UIView里设置按钮的事件能成功:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    self.customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 80)];
    self.myButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 20, 100, 40)];
    self.myButton.backgroundColor = [UIColor redColor];
    [self.myButton addTarget:self action:@selector(doButonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.customView addSubview:self.myButton];
    
    return self.customView;
}

但是,我把按钮公开,然后再controller里设置事件就不行。这是什么原因?

View:
@property (strong, nonatomic) UIButton *myButton;


controller:

CustomView *cv = [[CustomView alloc] initWithFrame:self.view.bounds ];
[cv.myButton addTarget:self action:@selector(doButtonAction11) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:cv];
PHP中文网PHP中文网2889일 전656

모든 응답(5)나는 대답할 것이다

  • 大家讲道理

    大家讲道理2017-04-18 09:08:05

    Target을 추가할 때 중단점을 잘라내고 myButton이 생성되는지 확인하세요. 메모리가 있나요?

    회신하다
    0
  • 高洛峰

    高洛峰2017-04-18 09:08:05

    블록을 만들고 클릭하면 호출하는 것이 좋습니다

    회신하다
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:08:05

    myButton이 초기화되었는지 확인해야 합니다.

    회신하다
    0
  • 阿神

    阿神2017-04-18 09:08:05

    이런 이벤트 전달을 시도해 본 적이 없습니다. 차단/위임/공지 기능을 사용하는 것이 좋습니다. 개인적으로는 객체가 생성되지 않는다고 생각합니다. 이를 인쇄하여 컨트롤러 개체가 있는지 확인합니다.

    회신하다
    0
  • 阿神

    阿神2017-04-18 09:08:05

    테이블뷰의 발 부분에 높이가 없어서 잘 보이지 않을 수도 있습니다.

    회신하다
    0
  • 취소회신하다