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;
}
;
}
私のすべてのチェックボックス