Note that there are some explanatory texts on larger screens.

plurals
  1. POadding and removing layer over UITableViewCell
    text
    copied!<p>i have a tableview of devices that may or not be connected. if a device is connected, there is an on/off switch (in accessory view) to control it. if it is disconnected, the switched is replaced by a disconnect symbol. so far,so good. Now, i want to add a layer to grey out the cell if it is disconnected, and obviously have the layer disappear if it is connected. (for testing, I just have this wired to a button to toggle state. I have figured out how to place the layer, but i can't remove it. click one-displays the layer, click two-does nothing, click three-makes layer even darker, etc. until it is completely black. the block is being called because with each click, i see the log statement:greyString is 1" or greyString is 0. i have tried [layer setHidden:YES],[layer removeFromSuperlayer] and layer.backroughColr=clearColor, to no effect</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath </code></pre> <p>{</p> <pre><code>UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } NamedUISwitch *mySwitch = [[NamedUISwitch alloc] initWithFrame:CGRectZero]; mySwitch.indexPath = indexPath; mySwitch.pathRow=indexPath.row; [mySwitch addTarget:self action:@selector(changeDeviceState:) forControlEvents:UIControlEventValueChanged]; cell.accessoryView=mySwitch; if ([[plugStates objectAtIndex:indexPath.row] isEqualToString:@"11"]) { cell.imageView.image=greenOn; mySwitch.on=YES; }else{ cell.imageView.image=greenOff; mySwitch.on=NO; } cell.backgroundView =[[UIImageView alloc] init]; cell.selectedBackgroundView =[[UIImageView alloc] init]; UIImage *rowBackground; UIImage *selectionBackground; NSInteger sectionRows = [self.tableView numberOfRowsInSection:[indexPath section]]; NSInteger row = [indexPath row]; if (row==1) { CALayer *mainLayer=cell.contentView.layer; CALayer *greyOut=[CALayer layer]; CGRect frame = [tableView rectForRowAtIndexPath:indexPath]; greyOut.frame=CGRectMake(0, mainLayer.frame.origin.y, frame.size.width, frame.size.height); CGColorRef darkColor = [[UIColor blackColor] colorWithAlphaComponent:.5f].CGColor; CGColorRef clearColor = [UIColor clearColor].CGColor; greyOut.backgroundColor=darkColor; [mainLayer addSublayer:greyOut]; if ([[[self.plugStates objectAtIndex:1] substringWithRange:NSMakeRange(0, 1)] isEqualToString:@"0"]){ [greyOut setHidden:NO]; cell.accessoryView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"disconnect70.png"]]; NSLog(@"greyString is 0"); }else{ NSLog(@"greyString is 1"); NSLog(@"superlayer is %@",greyOut.superlayer); greyOut.backgroundColor=clearColor; [greyOut setHidden:YES]; //[greyOut removeFromSuperlayer]; } } cell.textLabel.text = deviceName; return cell; </code></pre> <p>}</p>
 

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