我想在一个按钮上实现选择/取消选择所有功能,因此必须根据用户交互来选择和取消选择tableview单元格所有按钮。我已经选择了数组和未选择的数组,同时通过tableview单元格按钮进行选择。在给定的代码下方,通过indexPath方法在地窖行上单击tableview单元格按钮。
NSMutableDictionary *d=[_studentArr objectAtIndex:indexPath.row];
cell.studentId.text=[[d objectForKey:@"student_id"]description];
cell.rollNum.text=[[d `enter code here`objectForKey:@"class_roll_no"]description];
cell.firstName.text=[[d objectForKey:@"first_name"]description];
cell.lastName.text=[[d objectForKey:@"last_name"]description];
cell.attendanceStatus.text=[[d objectForKey:@"status"]description];
cell.studentFullName.text=[[[d objectForKey:@"first_name"]description] stringByAppendingString:[[d objectForKey:@"last_name"]description]];
NSLog(@"studentFullName.text=%@ status=%@",cell.studentFullName.text,cell.attendanceStatus.text);
NSLog(@"Student array count=%ld",_studentArr.count);
cell.studentSelectBtn.tag=indexPath.row;
NSLog(@"Selectted cell indexpath===%ld",(long)cell.studentSelectBtn.tag);
[cell.studentSelectBtn setTag:indexPath.row];
[cell.studentSelectBtn addTarget:self action:@selector(studentselectBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
if ([selectedArr containsObject:self.studentArr[indexPath.row]]) {
[cell.studentSelectBtn setImage:[UIImage imageNamed:@"checkedAttendance.png"] forState:UIControlStateNormal];
[cell.studentSelectBtn setUserInteractionEnabled:YES];
NSLog(@"attendance Status in checked ===%@",cell.attendanceStatus.text);
NSLog(@"selected array count=%ld",selectedArr.count);
}
else{
[cell.studentSelectBtn setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];
[cell.studentSelectBtn setUserInteractionEnabled:YES];
NSLog(@"attendance status in unchecked====%@",cell.attendanceStatus.text);
}
答案 0 :(得分:0)
您没有显示当前如何向selectedArr
添加/删除条目,但是从显示的内容来看,您可以将这两种方法关联为“全选” /“全选”的目标按钮:
-(void) selectAll {
self.selectedArr = [NSMutableArray arrayWithArray:self.studentArr];
[self.unselectArr removeAllObjects];
[self.tableView reloadData];
}
-(void) deselectAll {
[self.selectedArr removeAllObjects];
[self.unselectedArr = [NSMutableArray arrayWithArray:self.studentArr];
[self.tableView reloadData];
}