Edit: I'm starting a bounty on this one, as I'm looking for a "cleaner" solution with a UITableViewCell
subclass, rather than messing with the UITableView
delegate and datasource. Ideally, I'd like to see how could I also handle the UISlider
events. Thanks!
I am using a group-styled UITableView
and I have several cells that look like this:
Now, while I'm in editing mode, I'd like to have a UISlider
that sets the value of the right UILabel, so that the result would look like this:
Could someone point me to the right direction? I'm not even sure if I should do that by subclassing UITableViewCell
or in IB. Code snippets would be highly appreciated :)
Being a sucker for bounties, i sat down and experimented a bit. This is what i have found to be the cleanest solution :
You will make a custom cell class. As i read from your post, you have no problem with this, and I belive it really is the only way.
In the header file:
@interface TableCellSlider : UITableViewCell { UISlider *cellSlider; }
In the main file :
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { cellSlider = [[UISlider alloc] initWithFrame:CGRectMake(200, 10, 100, 20)]; [self addSubview:cellSlider]; cellSlider.hidden = YES; } return self; } - (void)didTransitionToState:(UITableViewCellStateMask)state { if (self.editing) { cellSlider.hidden = NO; } else { cellSlider.hidden = YES; } } - (float)getValue { return cellSlider.value; }
As for the table and the cell height, add this to the table script :
- (void)setEditing:(BOOL)editing animated:(BOOL)animated { [self.tableView beginUpdates]; [super setEditing:editing animated:YES]; [self.tableView endUpdates]; //[self.tableView reloadData]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (self.editing) { return 50; } else { return 30; } }
This should do the trick. You can use the getValue on the cells, so you don't have to synthesize the sliders, and they will hide/reappear for whatever reason the cells become editable.
Best of luck with your project :]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With