gpt4 book ai didi

ios - 分段控件中 TableView 中的 UIStepper

转载 作者:行者123 更新时间:2023-11-29 13:06:08 24 4
gpt4 key购买 nike

我有分段控件和每个分段控件的 onclick,显示一个 TableView ,其中有一个与每个单元格关联的 uistepper。一个段在其表上有 UIStepper,但当我在段之间切换时它仍然显示,可能来自其他段。我正在使用 addSubView 方法添加 uistepper。但是当切换到那个段时我如何删除它。

谢谢

编辑

    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];
}

最佳答案

你可以试试这个。

if ([cell.contentView subviews])
{
for (UIView *subview in [cell.contentView subviews])
{

if(subview.tag==123 || subview.tag==456)
[subview removeFromSuperview];

}
}

关于ios - 分段控件中 TableView 中的 UIStepper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18592528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com