【发布时间】:2024-01-16 03:36:01
【问题描述】:
我在UITableView viewForHeaderInSection 中创建了自定义UIButton。现在,当我单击该部分中的按钮时,我如何知道单击了哪个部分?请帮忙。
【问题讨论】:
-
按钮是静态的还是动态的?
标签: iphone uitableview uibutton
我在UITableView viewForHeaderInSection 中创建了自定义UIButton。现在,当我单击该部分中的按钮时,我如何知道单击了哪个部分?请帮忙。
【问题讨论】:
标签: iphone uitableview uibutton
当您在 viewForHeaderInSection 添加按钮时,只需设置带有节号的标签,如下所示。,..
button.tag = section;
当您点击按钮时,您可以使用以下代码获取该数字...
- (IBAction)yourButton_Clicked:(id) sender
{
NSLog(@"Section Number => %d",[sender tag]);
}
【讨论】:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIbutton *btn =[[UIButton alloc]init];
btn.tag=section;// this tag property will differentiate button for different section
}
通过这个,您可以访问 btn 并在该 burron 上添加事件
【讨论】:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIbutton *button =[[UIButton alloc]init];
button.tag=section;// this tag property will differentiate button for different section
}
【讨论】:
在 didselectrowatindexpath 检查 if(index path.section) 是否等于您想要操作的部分。
【讨论】: