Jua*_*lez 3 cocoa-touch objective-c ipad ios
我有一个UITableView,我希望用户能够点击两个按钮,在该部分的标题中,一个用于添加新记录,另一个用于编辑它们,所以我首先尝试使用tableView viewForHeaderInSection并tableView 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");
}
- (IBAction)onEditVehiclesInterest:(id)sender {
NSLog(@"Edit");
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我可以正确地看到三个UIBarButtonItems,我可以单击它们,但永远不会调用NSLog行.因此,我增加一个UIToolbar在笔尖文件直接,加入3个UIBarButtonItem控制到它,并绑在onAddVehicleInterest和onEditVehiclesInterest到相应的按钮.但那也不起作用......
因此,作为最后一次测试,我UIButton在nib中添加了一个并将其Touch Up Inside事件绑定到其中一个方法,并且按预期工作.所以我很困惑.我究竟做错了什么?
| 归档时间: |
|
| 查看次数: |
3604 次 |
| 最近记录: |