小编Jua*_*lez的帖子

UIBarButtonItem没有响应click

我有一个UITableView,我希望用户能够点击两个按钮,在该部分的标题中,一个用于添加新记录,另一个用于编辑它们,所以我首先尝试使用tableView viewForHeaderInSectiontableView heightForHeaderInSection像这样:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
     UIView* v = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 360, 44)];
    UIToolbar* tb = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 360, 44)];

    UIBarButtonItem* spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem* addBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(onAddVehicleInterest:)];
    UIBarButtonItem* editBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(onEditVehiclesInterest:)];

    [tb setItems:[NSArray arrayWithObjects:spacer, addBtn, editBtn, nil]];

    [v addSubview:tb];
    return v;
}

- (IBAction)onAddVehicleInterest: (id) sender {
    NSLog(@"Add"); …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c ipad ios

3
推荐指数
1
解决办法
3604
查看次数

标签 统计

cocoa-touch ×1

ios ×1

ipad ×1

objective-c ×1