在我的代碼中,我有一個表格視圖,其中有很多節按字母順序排序。我在錶行中有checkboxes(UIButton)
,我需要根據在行中輸入的相應狀態來檢查它們。我已經完成在IOS中獲取UITableView的行號
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或interface builder中創建? –