Note that there are some explanatory texts on larger screens.

plurals
  1. POUISwitch status change overlap
    primarykey
    data
    text
    <p>I have a problem with a <code>UISwitch</code> in a tableview cell.</p> <p>This switch is normally in On position, then when a variable changes its value the switch go to the Off position but I have a problem like the switch in the second row:</p> <p><img src="https://i.stack.imgur.com/KWe0U.png" alt="enter image description here"></p> <p>This is the simple code into the cellForRowAtIndexPath section:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; tableView.backgroundColor = [UIColor clearColor]; tableView.opaque = NO; tableView.backgroundView = nil; [tableView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage.png"]]]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } if ([self.title isEqualToString:@"Test"]) {cell.textLabel.text = [self.tester objectAtIndex: [indexPath row]];cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.accessoryType = UITableViewCellAccessoryNone; if (([indexPath row] == 5) || ([indexPath row] == 4)){ NSArray *segmentItems = [NSArray arrayWithObjects:@"Down", @"Up", nil]; UISegmentedControl *testSegmentedControl = [[UISegmentedControl alloc] initWithItems:segmentItems]; testSegmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth; testSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; testSegmentedControl.tintColor = [UIColor grayColor]; testSegmentedControl.frame = CGRectMake(160, 10, 150, 30); [testSegmentedControl setTag:[indexPath row]]; [[cell contentView] addSubview:testSegmentedControl]; [testSegmentedControl addTarget:self action:@selector(testing:) forControlEvents:UIControlEventValueChanged]; } else { mySwitch = [ [ UISwitch alloc ] initWithFrame: CGRectMake(200, 10, 0, 0) ]; mySwitch.tag = [indexPath row]; mySwitch.onTintColor = [UIColor grayColor]; if ([indexPath row] == 0){ if ([asd41 isEqualToString:@"False"]) mySwitch.on = NO; else mySwitch.on = YES; } if ([indexPath row] == 1){ if ([asd40 isEqualToString:@"False"]) mySwitch.on = NO; else mySwitch.on = YES; } if ([indexPath row] == 2){ if ([asd42 isEqualToString:@"False"]) mySwitch.on = NO; else mySwitch.on = YES; } if ([indexPath row] == 3){ if ([asd76 isEqualToString:@"False"]) mySwitch.on = NO; else mySwitch.on = YES; } [ cell addSubview: mySwitch ]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.2]; [mySwitch addTarget:self action:@selector(switch1:) forControlEvents:UIControlEventValueChanged];} } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload