Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom UITableViewCell with label and UISlider worked fine in 6 crashes in ios 7. ?? UITableViewCellScrollView?

I was going to post this as a Question but I worked it out and thought I'd share it in case anyone else ran into this.

I have a custom tableViewCell called SliderCell. I use a number of SliderCells on my table.

The SliderCell contains a UISlider and a UILabel.

When the user moves the slider the label is updated with a new value

This is in this method

- (IBAction)possibilityDidChange:(UISlider *)sender {

Now the sender in this case is the UISlider control

To set the value of UILabel I needed to get the tableviewCell (sliderCell) that the sender sits on.'

Originally i got this as follows

SliderCell *theAnimalCell =(SliderCell*)sender.superview.superview;

I could then set the label like this

theAnimalCell.sliderLabel.text = [NSString stringWithFormat:@"turtles %@",possibilityString];

All well and good when i was using Xcode 4.x and targeting iOS6.1

Now , after deciding that 200m+ cant be wrong I'm just targeting iOS 7 and suddenly I'm getting a crash as sooon as I touch any of my UISliders

I get this error

[UITableViewCellScrollView currentSlider]: unrecognized selector sent to instance

I couldn't find any reference to this class in the documentation.

like image 374
SimonTheDiver Avatar asked Dec 21 '25 05:12

SimonTheDiver


2 Answers

Inspecting the class i discovered what i was expecting to be a SLiderCell was in fact now a UITableViewCellScrollView. However if you go up another level by adding an extra .superview you do get to the custom UITableViewCell and it now works again

So the change was from

SliderCell *theAnimalCell =(SliderCell*)sender.superview.superview;

To this

SliderCell *theAnimalCell =(SliderCell*)sender.superview.superview.superview;

I guess if you wanted to support both iOS 7 and iOS 6 you would need to check before you tried to grab the custom cell.

Well, thats it , hope this proves useful to someone out there.

Simon

like image 56
SimonTheDiver Avatar answered Dec 23 '25 23:12

SimonTheDiver


Make a condition like this.

AddTOcartCell *cell = ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) ? (AddTOcartCell*)textField.superview.superview.superview : (AddTOcartCell*)textField.superview.superview;
cell.btnUpdate.hidden=FALSE;
NSLog(@"Call Y%f",cell.frame.origin.y);
[tblProduct setContentOffset:CGPointMake(0,cell.frame.origin.y) animated:YES];
like image 31
chetu Avatar answered Dec 23 '25 23:12

chetu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!