UILabel crashes the app when added to view (Xcode 6 and iOS 8 only)

I transferred my project to Xcode 6 to build for iOS 8. However, a specific UILabel crashes the application when it is added to the view hierarchy. This is the only error log I get:

-[MyViewController _contentInsetsFromFonts]: unrecognized selector sent to instance 0x16d90da0 

I was unable to find the contentInsetsFromFonts method contentInsetsFromFonts in my project. In addition, I could not even find a link to it anywhere on the Internet, including Apple documentation. I do not use NIB for this UIViewController, so the user interface is built in the loadView method:

 - (void)loadView { UIImage *trackImage = [UIImage imageNamed:@"sliderTrack.png"]; sliderBackground = [[UIImageView alloc] initWithImage:trackImage]; UIView *view = [[UIView alloc] initWithFrame:sliderBackground.frame]; [view addSubview:sliderBackground]; slider = [[UISlider alloc] initWithFrame:sliderBackground.frame]; CGRect sliderFrame = slider.frame; sliderFrame.size.width -= 46; slider.frame = sliderFrame; slider.center = sliderBackground.center; slider.backgroundColor = [UIColor clearColor]; [slider setMinimumTrackImage:[UIImage imageNamed:@"sliderMaxMinTrackImage.png"] forState:UIControlStateNormal]; [slider setMaximumTrackImage:[UIImage imageNamed:@"sliderMaxMinTrackImage.png"] forState:UIControlStateNormal]; UIImage *thumbImage = [UIImage imageNamed:@"cancel-slider.png"]; [slider setThumbImage:thumbImage forState:UIControlStateNormal]; slider.minimumValue = 0.0; slider.maximumValue = 1.0; slider.continuous = YES; slider.value = 0.0; // Set the slider action methods [slider addTarget:self action:@selector(sliderUp:) forControlEvents:UIControlEventTouchUpInside]; [slider addTarget:self action:@selector(sliderDown:) forControlEvents:UIControlEventTouchDown]; [slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; NSString *labelText = @"label text"; UIFont *labelFont; NSString *osVersion = [[UIDevice currentDevice] systemVersion]; if ([osVersion floatValue] >= 7.0) { labelFont = [UIFont systemFontOfSize:22.0]; } else { labelFont = [UIFont systemFontOfSize:24.0]; } CGSize labelSize = [labelText sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:labelFont, NSFontAttributeName, nil]]; label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, labelSize.width, labelSize.height)]; CGFloat labelHorizontalCenter = slider.center.x + (thumbImage.size.width / 2); label.center = CGPointMake(labelHorizontalCenter, slider.center.y); // Set other label attributes and add it to the view label.textColor = [UIColor whiteColor]; label.textAlignment = NSTextAlignmentCenter; label.backgroundColor = [UIColor clearColor]; label.font = labelFont; label.text = labelText; [view addSubview:label]; [view addSubview:slider]; label.layer.delegate = self; self.view = view; } 

Application is not broken into [view addSubview:label] ; it will work after the loadView method loadView .

+7
ios objective-c cocoa-touch ios8
source share
1 answer

From the UIView documentation :

Never change the delegate of this layer object.

Delete this line:

 label.layer.delegate = self; 

Whatever you try to do here, you will need to do it differently.

+13
source share

All Articles