0
私はこのtableViewのtableFooterViewにボタンを追加するとUIView.Itから継承するクラスにtableViewを作成します。Buttonはイベントに応答しないtableFooterViewで作成します
CustomView.h
#import <UIKit/UIKit.h>
@interface CustomView : UIView<UITableViewDelegate,UITableViewDataSource>
@end
CustomView.m
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView * customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 80)];
UIButton * tempButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
tempButton.center = customView.center;
tempButton.backgroundColor = [UIColor redColor];
[tempButton addTarget:self action:@selector(doButtonAction) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:tempButton];
return customView;
}
- (void)doButtonAction{
NSLog(@"123");
}
のNSLog:123
しかし、私は公共このボタンと私のcontroller.It応答何でターゲット・アクションを作ります。
CustomView.h
@property (strong, nonatomic) UIButton * tempButton;
CustomView.m
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView * customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 80)];
self.tempButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
self.tempButton.center = customView.center;
[customView addSubview:self.tempButton];
return customView;
}
ViewController.h
- (void)viewDidLoad {
[super viewDidLoad];
CustomView *cv = [[CustomView alloc] initWithFrame:self.view.bounds ];
[cv.tempButton addTarget:self action:@selector(doButtonAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:cv];
}
- (void)doButtonAction{
NSLog(@"123");
}
私は何を欠席しましたか?
これは私のせいです。私はコードを省略しました。実際には、このボタンはtableFooterViewに割り当てられています。十分に慎重に、このボタンは実際には '' viewDidLoad'''にはありません。 – ShakeAnimation
私たちは愚かな間違いをしばらくしています。 :) –