Ios 视图中的UI按钮用于标题部分
我想把一个信息灯按钮在一个部分标题Ios 视图中的UI按钮用于标题部分,ios,uibutton,tableview,Ios,Uibutton,Tableview,我想把一个信息灯按钮在一个部分标题 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 20; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *sectionHeaderView = [[U
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoButton.frame = CGRectMake(0, 0, 18, 18); // x,y,width,height
infoButton.enabled = YES;
[infoButton addTarget:self action:@selector(infoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//Add the subview to the UIView
[sectionHeaderView addSubview:infoButton];
return sectionHeaderView;
}
- (void)infoButtonClicked:(id)sender {
NSLog(@"infoButtonClicked");
}
按钮没有响应。我不太清楚为什么。这可能很简单。任何帮助都将不胜感激。我尝试了与您完全相同的代码(复制并粘贴)到一个正常工作的UITableView类中,它工作得很好。我能够点击按钮并获得调试输出。因此,上面显示的代码很好,应该可以工作。你班上肯定还有别的东西坏了 好的。我偶然发现了一个答案,我将与其他可能有类似问题的人分享 我有一个UIViewController,它有两个子视图——UIView和UITableView。在序列图像板中,我在序列图像板的文档大纲视图中有更高的UITableView。(可以使用左下角按钮打开的故事板的左侧视图面板)。我认为这意味着UITableView是一个较低的层,如果你把它看作一堆层的话
我切换了图层顺序(使UIView位于文档大纲视图的更高位置),一切正常。谢谢melsam。我也只是在一个示例项目中尝试过。很好。我应该先做那件事。我想我得再搔搔头了