체크 박스 형태로 사용하고있는 앱을 만들고 있습니다. 내가 시도하고 있지만 가능한 솔루션을 찾을 수 없습니다 .. 여기 내 프로젝트 링크 https://www.dropbox.com/s/iu8fdz4y0ps4xye/checkboxwithTableview%202.zip?dl=0 친절하게 텍스트 레이블에 확인란 수를 표시하고 싶습니다 그것을 검토하십시오 .. 아래는 내 샘플 코드입니다
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *tableviewidentifier = @"cell";
TablecellTableViewCell *cell= [self.tblvie dequeueReusableCellWithIdentifier:tableviewidentifier];
if(cell==nil)
{
cell = [[TablecellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableviewidentifier];
}
cell.lblImage.layer.cornerRadius=3.0f;
cell.lblImage.layer.borderWidth=1.0f;
if ([self.checkimageArray containsObject:[self.lblArray objectAtIndex:indexPath.row]])
{
[cell.buttonCheckbox setImage:[UIImage imageNamed:@"checkBox.png"] forState:UIControlStateNormal];
// [cell.buttonCheckbox setImage:[UIImage imageNamed:@"checkBoxMarked.png"] forState:UIControlStateNormal];
}
else
{
//[cell.buttonCheckbox setImage:[UIImage imageNamed:@"checkBox.png"] forState:UIControlStateNormal];
[cell.buttonCheckbox setImage:[UIImage imageNamed:@"checkBoxMarked.png"] forState:UIControlStateNormal];
}
cell.buttonCheckbox.tag=indexPath.row;
[cell.buttonCheckbox addTarget:self action:@selector(checkButton:) forControlEvents:UIControlEventTouchUpInside];
cell.lblText.text=[self.lblArray objectAtIndex:indexPath.row];
return cell;
}
-(IBAction)checkButton:(UIButton *)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tblvie];
NSIndexPath *indexPath = [self.tblvie indexPathForRowAtPoint:buttonPosition];
if ([self.checkimageArray containsObject:[self.lblArray objectAtIndex:indexPath.row]]) {
[self.checkimageArray removeObject:[self.lblArray objectAtIndex:indexPath.row]];
self.titleLabel.text=@"";
}
else {
[self.checkimageArray addObject:[self.lblArray objectAtIndex:indexPath.row]];
NSArray *arr=[self.tblvie indexPathsForSelectedRows];// here i am declaring an array but array is coming nil
self.titleLabel.text=[self.lblArray objectAtIndex:indexPath.row];
}
[self.tblvie reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
}
.h에 Int 변수를 추가 int checkBoxesCount;
하십시오. ViewDidLoad에서 초기화하십시오.checkBoxesCount = 0;
아래와 같이 방법을 업데이트하십시오.
-(IBAction)checkButton:(UIButton *)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tblvie];
NSIndexPath *indexPath = [self.tblvie indexPathForRowAtPoint:buttonPosition];
if ([self.checkimageArray containsObject:[self.lblArray objectAtIndex:indexPath.row]]) {
[self.checkimageArray removeObject:[self.lblArray objectAtIndex:indexPath.row]];
checkBoxesCount = checkBoxesCount - 1;
self.titleLabel.text=[NSString stringWithFormat:@"Count %d",checkBoxesCount];
}
else {
[self.checkimageArray addObject:[self.lblArray objectAtIndex:indexPath.row]];
// self.titleLabel.text=[self.lblArray objectAtIndex:sender.tag];
checkBoxesCount = checkBoxesCount + 1;
self.titleLabel.text=[NSString stringWithFormat:@"Count %d",checkBoxesCount];
}
[self.tblvie reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];
}
문제가 해결되었습니다. 나는 내 끝에서 똑같이 테스트했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다