【发布时间】:2013-07-19 10:11:11
【问题描述】:
在我的代码中,我有一个表格视图,其中许多部分按字母顺序排序。我在表格行中有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 中的确切行号。
【问题讨论】:
-
你为什么在那个事件中创建复选框按钮,而不是在 getCellForRowAtIndex 或界面生成器中?
标签: iphone ios objective-c uitableview