1

セグメント化されたコントロールと各セグメント化されたコントロールの onclick があり、各セルに関連付けられた uistepper を持つテーブルビューが表示されます。1 つのセグメントはテーブルに UIStepper を持っていませんが、他のセグメントからセグメントを切り替えると表示されます。addSubView メソッドを使用して uistepper を追加しています。しかし、その1つのセグメントに切り替えたときにそれを削除するにはどうすればよいですか.

ありがとうございました

編集

    if(selectedSegment == 0){
        cell.textLabel.text=[selectedJointWork objectAtIndex:indexPath.row];
        cell.textLabel.font=[UIFont fontWithName:@"Times New Roman" size:17.f];

    }

    if(selectedSegment == 1){
        cell.textLabel.text=[selectedSampling objectAtIndex:indexPath.row];
        cell.textLabel.font=[UIFont fontWithName:@"Times New Roman" size:17.f];

        UILabel *lbl1 = [[UILabel alloc] init];
        lbl1.frame = CGRectMake(400, 16, 35 ,12);
        [lbl1 setBackgroundColor:[UIColor clearColor]];
        //lbl1.text = @"1";
        //lbl1.text = [quantityArray objectAtIndex:indexPath.row];
        [cell.contentView addSubview:lbl1];

        [lbl1 setTag:456];

        UIStepper* stepper = [[UIStepper alloc] init];
        stepper.frame = CGRectMake(450, 10, 100, 10);

        [cell.contentView addSubview: stepper];

        stepper.minimumValue = [[samplingQuantity objectAtIndex:indexPath.row] intValue];

        [stepper setTag:123];
        [stepper addTarget:self action:@selector(stepperOneChanged:) forControlEvents:UIControlEventValueChanged];

        int count = [[samplingQuantity objectAtIndex:indexPath.row] intValue];

        [(UIStepper*)[cell viewWithTag:123] setValue:count];
        [(UILabel*)[cell viewWithTag:456] setText:[NSString stringWithFormat:@"%d",count]];
    }

以下はセグメントスイッチ方法です

- (IBAction)segmentSwitch:(id)sender {

UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;

[table2 reloadData];

if (selectedSegment == 0) {
    [jointWork removeAllObjects];
    AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
    self.managedObjectContext=appDelegate.managedobjectcontext;

    NSFetchRequest * fetch = [[[NSFetchRequest alloc] init] autorelease];
    [fetch setEntity:[NSEntityDescription entityForName:@"VisitedWith" inManagedObjectContext:self.managedObjectContext]];
    NSArray * result = [self.managedObjectContext executeFetchRequest:fetch error:nil];
    for (NSDictionary *dic in result)
    {
        [jointWork addObject:[dic valueForKey:@"vname"]];
        [Itemsids addObject:[dic valueForKey:@"vid"]];
    }

    if([jointWork count] == 0){
        UIAlertView *save = [[[UIAlertView alloc]
                              initWithTitle:@"Not Found!"
                              message:@"Data not Found"
                              delegate:self
                              cancelButtonTitle:@"Ok"
                              otherButtonTitles: nil] autorelease];
        [save show];
    }

    [table reloadData];

}
else if(selectedSegment == 1){
    [sampling removeAllObjects];
    AppDelegate *appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
    self.managedObjectContext=appDelegate.managedobjectcontext;

    NSFetchRequest * fetch = [[[NSFetchRequest alloc] init] autorelease];
    [fetch setEntity:[NSEntityDescription entityForName:@"Sampling" inManagedObjectContext:self.managedObjectContext]];
    NSArray * result = [self.managedObjectContext executeFetchRequest:fetch error:nil];
    for (NSDictionary*dic   in result)
    {
        NSLog(@"Object At index%@",[dic valueForKey:@"productname"]);

        [sampling addObject:[dic valueForKey:@"productname"]];
        [Itemsids addObject:[dic valueForKey:@"productid"]];
    }
    if([sampling count] == 0){
        UIAlertView *save = [[[UIAlertView alloc]
                              initWithTitle:@"Not Found!"
                              message:@"Data not Found"
                              delegate:self
                              cancelButtonTitle:@"Ok"
                              otherButtonTitles: nil] autorelease];
        [save show];
    }

    [table reloadData];
}

}

4

1 に答える 1