<分区>
在我的代码中,我有一个 TableView ,其中许多部分按字母顺序排序。我在表行中有 checkboxes(UIButton)
,我需要根据行中输入的各自状态检查它们。我做过
checkbutton.tag = indexpath.row;
但是当表格滚动和部分发生变化时,我在我的复选框方法中获得了上一节的状态。任何人都请帮助我。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CheckButton = [UIButton buttonWithType:UIButtonTypeCustom];
[CheckButton addTarget:self action:@selector(CheckBoxAction:) forControlEvents:UIControlEventTouchUpInside];
CheckButton.tag=indexPath.row;
//some other stuff
[cell.contentView addSubview:CheckButton];
}
这是我的 CheckBoxAction
-(void)CheckBoxAction:(UIButton *)btn
{
tag = btn.tag;
NSDictionary *tagdict =[statusArray objectAtIndex:tag];
}
现在,问题是当部分更改时 indexpath.row
为 0,因此我无法在我的 CheckBoxAction
中访问确切的行号。