0
하이, 모든 행의 확인란을 인쇄하고 있습니다.하지만 임의의 체크 박스를 선택하면 마지막 셀 체크 박스 만 선택됩니다. 체크 박스와 일별, 주별, 월별 데이터를 인쇄하는 코드가 아래에 있습니다. Tableview 셀에서 확인란에 액세스하는 방법?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [[UITableViewCell alloc]init];
cell = [self getCellContentView:CellIdentifier];
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
UILabel *lblTemp3 = (UILabel *)[cell viewWithTag:3];
UILabel *lblTemp4 = (UILabel *)[cell viewWithTag:4];
checkButton=[UIButton buttonWithType:UIButtonTypeCustom];
checkButton.frame = CGRectMake(5,30, 15, 10);
[checkButton addTarget:self action:@selector(SelectCheckBox) forControlEvents:UIControlEventTouchUpInside];
pictureimageView=[[UIImageView alloc]initWithFrame:CGRectMake(20, 5, 100, 60)];
//pictureimageView=[[UIImageView alloc]initWithFrame:CGRectMake(2, 3, 65, 65)];
[pictureimageView.layer setBorderColor:[[UIColor grayColor] CGColor]];
[pictureimageView.layer setShadowColor:[[UIColor grayColor] CGColor]];
[pictureimageView.layer setMasksToBounds:YES];
[pictureimageView.layer setBorderWidth:1.5];
[pictureimageView.layer setCornerRadius:5.0];
[pictureimageView.layer setShadowRadius:1.0];
[pictureimageView.layer setShadowOpacity:3.0];
if(selectedSegment==0)
{
databasefields=[eventData objectAtIndex:indexPath.row];
lblTemp1.text=databasefields.DBtitle;
lblTemp2.text=databasefields.DBlocation;
lblTemp3.text=databasefields.DBdate ;
lblTemp4.text=databasefields.DBtime;
//NSString *pictureString=[[NSString alloc]init];
pictureString=databasefields.DBpicture;
checkimage = [UIImage imageNamed:@"checkbox.PNG"];
[checkButton setImage:checkimage forState:UIControlStateNormal];
pictureimageView.image = [UIImage imageWithContentsOfFile:pictureString];
[cell.contentView addSubview:checkButton];
[cell.contentView addSubview:pictureimageView];
}
else
if(selectedSegment==1)
{
databasefields=[eventData objectAtIndex:indexPath.row];
lblTemp1.text=databasefields.DBtitle;
lblTemp2.text=databasefields.DBlocation;
lblTemp3.text=databasefields.DBdate;
lblTemp4.text=databasefields.DBtime;
pictureString=[[NSString alloc]init];
pictureString=databasefields.DBpicture;
checkimage = [UIImage imageNamed:@"checkbox.PNG"];
pictureimageView.image = [UIImage imageWithContentsOfFile:pictureString];
[cell.contentView addSubview:checkButton];
[cell.contentView addSubview:pictureimageView];
}
else if(selectedSegment==2)
{
databasefields=[eventData objectAtIndex:indexPath.row];
lblTemp1.text=databasefields.DBtitle;
lblTemp2.text=databasefields.DBlocation;
lblTemp3.text=databasefields.DBdate;
lblTemp4.text=databasefields.DBtime;
pictureString=[[NSString alloc]init];
pictureString=databasefields.DBpicture;
checkimage = [UIImage imageNamed:@"checkbox.PNG"];
[checkButton setImage:checkimage forState:UIControlStateNormal];
pictureimageView.image = [UIImage imageWithContentsOfFile:pictureString];
[cell.contentView addSubview:checkButton];
[cell.contentView addSubview:pictureimageView];
}
// Configure the cell...
return cell;
}
-(void) SelectCheckBox
{
if (checkboxSelected == 0){
[checkButton setSelected:YES];
checkimage = [UIImage imageNamed:@"checkbox-on.PNG"];
[checkButton setImage:checkimage forState:UIControlStateNormal];
checkboxSelected = 1;
} else {
[checkButton setSelected:NO];
checkimage = [UIImage imageNamed:@"checkbox.PNG"];
[checkButton setImage:checkimage forState:UIControlStateNormal];
checkboxSelected = 0;
}
;
}
세포에 대해 배울 수
Table View Programming Guide을 읽어주십시오 모든 체크 박스