IB_DESIGNABLE, IBInspectable -- Interface builder does not update - ios

I have the following set of code:
CustomView.h
#import <UIKit/UIKit.h>
IB_DESIGNABLE
#interface CustomView : UIView
#property (nonatomic) IBInspectable UIColor *borderColor;
#property (nonatomic) IBInspectable CGFloat borderWidth;
#property (nonatomic) IBInspectable CGFloat cornerRadius;
#end
CustomView.m
#import "CustomView.h"
#implementation CustomView
- (void)setBorderColor:(UIColor *)borderColor {
_borderColor = borderColor;
self.layer.borderColor = borderColor.CGColor;
}
- (void)setBorderWidth:(CGFloat)borderWidth {
_borderWidth = borderWidth;
self.layer.borderWidth = borderWidth;
}
- (void)setCornerRadius:(CGFloat)cornerRadius {
_cornerRadius = cornerRadius;
self.layer.cornerRadius = cornerRadius;
}
#end
(For Swift reference, this problem was also occurring with Swift code)
CustomView.swift
#IBDesignable
class CustomView : UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
#IBInspectable var borderColor : UIColor = UIColor.clearColor() {
didSet {
self.layer.borderColor = borderColor.CGColor
}
}
#IBInspectable var borderWidth : CGFloat = 0.0 {
didSet {
self.layer.borderWidth = borderWidth
}
}
#IBInspectable var cornerRadius : CGFloat = 0.0 {
didSet {
self.layer.cornerRadius = cornerRadius
}
}
}
I added a UIView to a view controller on the storyboard and set its subclass to CustomView.
This adds the "Designables" row. It is stuck on "Updating" and the tooltip says "Waiting for Target to Build". It never changes from this status.
When I move to the attributes inspect, I am able to set these IBInspectable properties:
And once set, they also show up in the "User Defined Runtime Attributes":
However, the "Designables" status never moves beyond "Updating" with still the same tooltip (I've tried Cmd+B building several times, nothing changes).
Moreover, as I set the IBInspectable properties, I get a warning for each one:
IBDesignables - Ignoring user defined runtime attribute for key path "borderColor" on instance of "UIView" ... this class is not key-value coding-compliant for the key borderColor.
Screenshot of the warnings generated:
I am familiar with the key-value coding-compliant issues and generally know how to solve them... but I don't understand how to solve this issue here. According to the view's identity inspector, the view is a "CustomView" (not a regular "UIView", which doesn't have these properties). And if the view weren't a "CustomView" then these designable properties wouldn't show up in the Attributes Inspector, right? But when Interface Builder tries to apply these attributes to the view, it goes back to thinking the view's class is "UIView" and cannot apply the attributes.
Any help? Please let me know if I've left out some important detail, but for what it's worth, I followed this tutorial exactly (other than ObjC vs Swift). It's also worth noting that I followed this tutorial exactly on another machine and it worked like a charm (I intended to make this post last night but the computer I was on then didn't have this issue).
Based on comments, it has been suggest that perhaps the .m file isn't included and that might be causing the problem. I thought surely I would have gone out of my way for this scenario to be the case, but I checked anyway.
When I first started attempting to do this, I was under the understanding that the IB_DESIGNABLE classes had to be part of a different UIKit framework. So from this first screenshot, you can see that I set up a "CustomViews" framework, which has one class, CustomView. You'll also see here that I also created a OtherView, which is identical to CustomView, except it's not in a separate framework. The identical problem persists on the storyboard between both classes however.
Here we have a screenshot indicating that CustomView.m is included to be built with the CustomViews framework:
Meanwhile, the following screenshot indicates several things:
CustomViews.framework is appropriately included in the main project.
OtherView.m is also included as a compile source, so even if something is wrong with CustomView, OtherView should work, however it generates identical errors.
Main.storyboard and LaunchScreen.xib are showing up as red. I have no idea why, and haven't the slightest clue as to why LaunchScreen.xib should (I haven't touched this file), though I can say after looking at other projects, Main.storyboard also shows up in red for those projects, and I'm not doing anything with IB_DESIGNABLE or IBInspectable there.
I have tried and retried this several times now. It works every time on my computer at home--I can not reproduce the problem described in this question at home. At work, it never works. The problem described in this question happens every time.
Both computers are Mac Minis purchased new this year (not the new models, late 2012 model). Both computers are running OS X Yosemite 10.10. Both computers are running Xcode Version 6.1. At home, the build is (6A1052d). This morning, I can confirm that both computers are running identical builds of Xcode.
Others have suggested to me that it might be bad RAM. That seems far fetched to me. I've restarted the project multiple times, restarted the computer multiple times. Seems to me if there were bad RAM on a computer approximately 6 months old, that I'd be seeing other problems, and that this problem would be less consistent. But this exact problem persists despite numerous times restarting the entire project from scratch and full restarts on the computer.
It should be worth noting that if I actually compile and run this project, the custom view with the IBInspectable properties actually displays as I expect the storyboard to display it. I imagine that this would be the case even with out the IB_DESIGNABLE and IBInspectable directives however, as these are created as User Defined Runtime Attributes.

Based on chrisco's suggestion to debug the selected view (which I had already done, but went to try again for good measure), I noticed a couple of other options at the bottom of the Editor menu.
Automatically Refresh Views
Refresh All Views
I clicked "Refresh All Views" and after Xcode had a bit of a think, suddenly the storyboard was displaying my view as expected (properly applying my IBInspectable properties).
I then went through the whole process again to confirm that this is the solution.
I created a new class, ThirdView. This class is identical to the others, again. I changed my view's class to ThirdView and got something slightly different this time:
Clicking "Show" to me to the warnings:
A new one this time:
Using class UIView for object with custom class because the class ThirdView does not exist.
This isn't really any more helpful than what already existed. Plus, now the other three warnings have doubled into 6 strangely.
Anyway, if I click "Refresh All Views" from the Editor drop down menu again, all the errors go away, and once again, the view properly displays.
Still, up to this point, everything I did was stuff I never messed with at home. At home, it just worked. So I turned on "Automatically Refresh Views" and created a "FourthView" to test--once again, identical to the first three.
After changing the view's class to "FourthView" the designables label said "Updating" for a short moment then finally said "Up to date":
So, I checked my computer at home. "Automatically Refresh Views" is turned on at the computer that was always working. It was turned off at the computer that wasn't. I don't ever remember touching this menu option. I can't even tell you for sure whether it existed before Xcode 6. But this option is what was making the difference.
TL;DR, if you're having the same problem described in the question, make sure "Automatically Refresh Views" is turned on (or manually "Refresh All Views" when you need an update in IB):

Just a quick hint for anyone else having this problem: remember to specify the type of the variable.
// Doesn't show up in IB
#IBInspectable var includeLeftSection = true
// Shows now that it knows the type
#IBInspectable var includeLeftSection : Bool = true

I have a few more details that may cause your IBDesignable classes to not be loaded.
Select your problematic storyboard/xib where your custom views ought to display.
In the navigator area, head to the Report Navigator in your XCode workspace/project.
In the Editor menu of XCode, hit (as mentioned by nhgrif), the "Refresh All Views" option. This will cause IB to launch a compile for a whole bunch of stuff that you, I'm certain, would not expect.
In the Report Navigator, Click on "By Group" to filter content and look at the "Interface Builder" section. You will see that for the sake of loading the custom IBDesignable views framework, it will compile LOTS of things. If any of these targets do NOT compile, such as (perhaps deprecated) unit test targets (even if they are totally unrelated to the code that loads these views or storyboard), then IB will fail at loading your dll.
In my case, IB tried to compile 8 targets, including 4 that where unit tests that had not been updated since recent refactoring changes we've been working on.
Most of the code changes/fixes I have done in order for IB to properly load and display my customs views where not related or even linked against these classes, nor would it ever load the storyboard in the course of running these unit tests. Yet, IB had a dependency on the whole workspace compiling for it to work.

I had the same warning Ignoring user defined runtime attribute for key path .. even though I am absolutely sure I didn't do anything wrong with my custom IBDesignable view class.
Turned out, in my case, it got to do with Xcode cache.
rm -rf ~/Library/Developer/Xcode/DerivedData/*
Purge DerivedData and the warning is gone.

Incase any one else comes up against the error IB Designables class does not exist, for the same reason as I did. Top answer was not my issue... but here is a slightly related problem...
There is a property hidden in the story board source code called customModule.
For example I had a class called ForwardArrow inside a separate framework that I accidentally added to my main target.
So the XML for some views ended up as
customClass="ForwardArrow" customModule="MainTargetNameWasHere"
When I removed them from the main target in the build the story board did not update MainTargetNameWasHere to CustomViews which is the framework where it was located and started giving that no class found error.
So TLDR; Make sure that if your IBDesignable is in another framework that the customModule xml attribute in your story board is set to the right value. And if it isn't there at all add it.
Example from my source:
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="MUG-jc-2Ml" customClass="ForwardArrow" customModule="CustomViews">

As my example, I was using CheckboxButton via pod and the graphics of checkbox never shows up in the storyboard while I got the same issues described in the question here:
warning: IB Designables: Using class UIView for object with custom class because the class CheckboxButton does not exist
and
warning: IB Designables: Ignoring user defined runtime attribute for key path "checkColor" on instance of "UIView". Hit an exception when attempting to set its value: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key checkColor.
The way solved my problem was to supply the module with name CheckboxButton as below:
Note: you should replace CheckboxButton to whatever the name of module you are using.

I personally solved this problem by using the "-" button to delete content from my identity inspector. When you remove custom classes, change content in the IB and then add a new custom class, the designable elements in the identity inspector don't get removed and it caused me to have that error. Just Delete everything and rebuild.

I know this is answered, but here is one more experience.
I was having some problems unrelated to this issue, but in the process I removed #IBInspectable from the vars in my class and deleted the attributes from the identity inspector (alt-apple-3).
After fixing the (code) issue with the component, I refreshed everything a ton of times, but still no attributes in the identity inspector.
Eventually, I noticed that they were back, but only in the attributes inspector (alt-apple-4). As soon as I added values to them there, they re-appeared in the identity inspector

Dave Thomas's answer above gave me the (reverse) solution when not of the others (Derived Data, Editor > Refresh) did, but for the sake of clarity in case people aren't sure where to edit the XML... you don't need to!
In your storyboard file select the troublesome view
On the right-hand sidebar select the Identity Inspector tab (3rd option from the left).
You'll have your custom class, which should already be set, and the Module. For me this was empty, and I was getting the same errors as OP. I set the Module to my project name and BAM - it started working after rebuilding!

I just went through the ringer on this problem. I tried all the things listed here and elsewhere without any luck. This is a storyboard that worked fine forever and it suddenly stopped working with the "Ignoring user-defined runtime attribute..." problem.
For whatever reason, removing this code from one of my IBDesignable's fixed it:
-(void)viewDidLoad {
self.clipsToBounds = YES;
}
removing this caused all the warnings to go away, even in other IBDesignable objects. I have no idea why this one step fixed it, but maybe it will help someone else too.

I was having the same problem and I had to change the cornerRadius and BorderWidth to be a String and then cast it to CGFloat, it was the only solution for me to be able to change the values and see the changes in interface builder.
#IBInspectable var borderColor: UIColor? {
didSet {
layer.borderColor = borderColor!.CGColor
}
}
#IBInspectable var borderWidth: String? {
didSet {
layer.borderWidth = CGFloat(Int(borderWidth!) ?? 0)
}
}
#IBInspectable var cornerRadius: String? {
didSet {
layer.cornerRadius = CGFloat(Int(cornerRadius!) ?? 0)
layer.masksToBounds = layer.cornerRadius > 0
}
}

Related

IBInspectable Properties not showing up in Xcode 8.3.3

While attempting to modify the Apple tutorial found here on IBinspectable properties for my own project I have run into a major roadblock.
I defined a simple button subclass:
import UIKit
#IBDesignable public class SocialMediaLoginButton: UIButton {
private var _loginType: SocialMediaLoginType = .facebook
#IBInspectable public var loginType: SocialMediaLoginType
= SocialMediaLoginType.facebook {
didSet {
self._loginType = loginType
}
}
}
And then added a UIButton to my storyboard which I then selected the CustomClass as the above type. When I switch over to the Attributes inspector the property is not there for me to adjust. I have no idea what is going on:
I have looked up other questions however there are either extremely outdated or have no answers on the app developer forum.
I have tried:
Manually refreshing the views
closing and reopening xcode
removing and re-adding the control
adding different controls like UIView and attempting same thing
None of these have worked. I am at a loss for how to fix this. I am using Xcode 8.3.3
Interface Builder supports the inspection of basic types (and their corresponding optionals), including: Booleans, numbers, strings, as well as CGRect, CGSize, CGPoint, and UIColor.
I think your type does not work with interface builder.
To add to Wilson answer, you MUST EXPLICITLY specify the type (Int, String, etc.) for it to show.

#IBDesignable - view not rendering as expected

I have a custom UIView subclass that I am trying to render using #IBDesignable.
I have an#IBInspectable property named image, which I set from the interface builder.
When I open the interface builder the image that I choose is not rendered properly in the view, that is, it looks like some trouble with autolayout.
When I checked the Report navigator I am getting a warning in the Interface Builder group.
Showing All Messages
(null): -pie being ignored. It is only used when linking a main executable
This happens under the Link <IBDESIGNABLE_EXECUTABLE> section.
I have no idea how to fix this. Tried many solutions from SO. Cleaning build folder, clearing derived data etc. Nothing worked.
Please provide your valuable comments or a solution to this problem. Thanks! :)
EDIT:
Thanks to #Rob I could zero in to the problem.
What I have:
An IBDesignable UIView Subclass with properties:
an#IBInspectable property named image.
an ImageView
a ScrollView
I initialise and add the ScrollView and ImageViews as subviews using
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialiseImageView()
}
override init(frame: CGRect) {
super.init(frame: frame)
initialiseImageView()
}
Problem:
In initialiseImageView():
I add the scrollView as subview of the UIView and ImageView as the subview of the scrollView to use the viewForZooming delegate. I also add constraints to keep the views in place.
The problem is when I use:
self.translatesAutoresizingMaskIntoConstraints = false
If I use this I get autolayout warnings at runtime. But the imageView is misplaced in interface builder, although the image is rendered correctly.
If I comment the same, everything is as expected in interface builder. But the UI breaks at runtime due to AutoresizingMaskIntoConstraints.
I have the code in github. I am trying the latter approach mentioned in TN2154
I am setting all AutoresizingMaskIntoConstraints to be false and adding the constraints for the subviews in the code itself. The constraints for the UIView subclass are added in the interface builder directly and no warnings exist as of now. The code works as expected at runtime also. The IBDesignable part is the one that is not working as expected.
Strangely enough, When I removed the line
self.translatesAutoresizingMaskIntoConstraints = false
everything is working perfectly. The error that I used to get at runtime is now gone. I don't know if something else that I did fixed it. Thanks a lot for helping to pin point the issue #Rob.
BTW, I just did a quick #IBDesignable with an #IBInspectable that was a UIImage and a draw(rect:) that rendered that image and it worked fine:
#IBDesignable class CustomView: UIView {
#IBInspectable var image: UIImage?
override func draw(_ rect: CGRect) {
image?.draw(at: CGPoint.zero)
}
}
When I do that in a separate target (as one should with designables), I also see the same warning:
ld: warning: -pie being ignored. It is only used when linking a main executable
I suspect that warning may be a red herring. The man pages for ld described -pie option as follows:
This makes a special kind of main executable that is position independent (PIE).
You can toggle this setting if you go to the link settings for your designables' target and change the "Generate Position-Dependent Executable" in the "Linking" settings. Then that warning will go away. Personally, I've never noticed that warning and never changed this settings, and never noticed any adverse affects, but if you want to confirm this for your own sense of satisfaction, try changing this setting and see if you can get the warning to go away.
Bottom line, your #IBDesignable problem probably rests elsewhere, but it's hard to diagnose on the basis of the information provided. We need more information (or, ideally, a MCVE).
It's hard to comment on your autolayout warnings without seeing what those warning are, but I'd guess that (a) you're adding a subview; but (b) not setting the constraints for said subview; and therefore (c) that when you set translatesAutoresizingMaskIntoConstraints = false, that your constraints are ambiguous and therefore result in error messages and unexpected layout at runtime. Or maybe it's a symptom of the idiosyncrasies of scroll views. But it's hard to say without seeing (a) actual autolayout error; (b) what subviews your #IBDesignable added; and (c) what constraints you added for your subviews.
Bottom line, make sure that your programmatically added subviews have all of their constraints unambiguously defined. Also remember that constraints for scrollview subviews act differently that many constraints, defining the contentSize of the scroll view rather than the size of the subviews. (On this latter point, see TN2154.)
For me, I deleted some no longer existing ibdesignable variables.
They were stuck in the User defined runtime attributes.
Deleting that, and then cleaning build folder, rebuilding resolved this for me!

UIButton with IB_DESIGNABLE throws runtime attribute warning and does not render in Interface Builder

I'm running Xcode 6.1 and I have been using IB_DESIGNABLE with IBInspectable for quite a few projects already but all of the sudden it just doesn't work anymore. I have created subclassed buttons that arrange the image and the title vertically centred above each other and enable the user to set a border width and color through IB with IBInspectable.
The following warning is logged and there is no preview available of my code in drawRect:
warning: IB Designables: Ignoring user defined runtime attribute for key path "spacingBetweenLabelAndImage" on instance of "UIButton". Hit an exception when attempting to set its value: [<UIButton 0x7f9278591260> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key spacingBetweenLabelAndImage.
Still, runtime it renders like I intended it to render and it also honours that same custom spacing I've added through IB.
Here's the code of the menubutton that rearranges the button and the title:
#import "HamburgerButton.h"
IB_DESIGNABLE
#interface HamburgerImageButton : HamburgerButton
#property IBInspectable CGFloat spacingBetweenLabelAndImage;
#end
Implementation:
#import "HamburgerImageButton.h"
#implementation HamburgerImageButton
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGSize imageSize = self.imageView.frame.size;
CGSize titleSize = self.titleLabel.frame.size;
// Move the label left and the image right by half the width
CGFloat leftInset = titleSize.width / 2;
CGFloat rightInset = imageSize.width / 2;
CGFloat halfSpacing = self.spacingBetweenLabelAndImage == 0 ? 0 : self.spacingBetweenLabelAndImage / 2;
CGFloat topInset = imageSize.height / 2 + halfSpacing;
CGFloat bottomInset = titleSize.height / 2 + halfSpacing;
UIEdgeInsets imageInsets = UIEdgeInsetsMake(-bottomInset, leftInset, bottomInset, -leftInset);
UIEdgeInsets titleInsets = UIEdgeInsetsMake(topInset, -rightInset, -topInset, rightInset);
self.imageEdgeInsets = imageInsets;
self.titleEdgeInsets = titleInsets;
}
#end
You've probably noticed it inherits HamburgerButton. This basic hamburger button does not have an image and it only draws the border around the button. This basic hamburger button has exactly the same problem: it does not draw it's border in drawRect in IB and it has the same type of errors. Here's that code for sake of completeness:
#import <UIKit/UIKit.h>
IB_DESIGNABLE
#interface HamburgerButton : UIButton
#property IBInspectable CGFloat borderWidth;
#property IBInspectable UIColor *borderColor;
#end
Implementation:
#import "HamburgerButton.h"
#import <QuartzCore/QuartzCore.h>
#implementation HamburgerButton
- (void)copyInspectables {
self.layer.borderWidth = self.borderWidth;
self.layer.borderColor = self.borderColor.CGColor;
}
- (void)drawRect:(CGRect)rect {
[self copyInspectables];
}
#end
I don't really understand why it just throws a warning and nothing else. I didn't really change what I did. I've checked the storyboard, it's iOS 7 and up, meant to run in Xcode 6 (latest).
It complains about not being able to find that value on UIButton and that's a bit weird because I've subclassed it.
Update:
So I changed everything around and it worked. Now it craps out again, without changing anything else. I think there's a bug in Xcode 6.1... :/
I have been working extensively with Live Views since it's introductions and like a lot of new features in Xcode initially, it has some flaws. Still I like it a lot and I hope that it will be improved in newer versions.
Cause:
Live Views work with #property properties that get a special IB_Designable tag that will give the UI class extra attributes it can approach via User Defined Runtime Attributes that will be set through the Attributes Inspector. You will see that all those properties also exist in the Identity Inspector. The root cause of the problem is that it cannot map those User Defined Runtime Attributes anymore to exposed properties.
As soon as you open up a Storyboard or xib that uses IB_Designable, Xcode will recompile the screen at every change if you have "Automatically Refresh Views" turned on. Since your code influences your UI as well this doesn't have to be a change in Interface Builder per se.
With simpler projects on faster machines this works pretty well the majority of the time. With larger projects that also have more IB_Designable the CPU simply doesn't have enough capacity to keep up with you and you will get a sort of time-out error while rendering the UI. This is the cause of the "warning: IB Designables: Ignoring user defined runtime attribute for key path "spacingBetweenLabelAndImage" on instance of "UIButton". Hit an exception when attempting to set its value: [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key spacingBetweenLabelAndImage." error.
It will also not update your UI anymore with your custom code. This is not a problem when you run it though, because at run time it will reflect those changes.
Another cause can be that your code simply doesn't compile when it tries to compile in the background. This is inevitable when you are working on code so that triggers it frequently as well.
Solution:
We need to make sure that your custom view class compiles again so the properties can be set successfully via Interface Builder
While in a storyboard, go to "Editor" in the top bar menu
deselect "Automatically refresh views" if it was still turned on
Close all your storyboard tabs
Rebuild the project
Fix all build errors if any
Re-open your storyboard.
Go to "Editor" again and click "Refresh All Views"
The warnings should be gone and if it worked before you will see your custom view code again as well.
After a comment below by sunkas: it's always a very good idea to clean your solution thoroughly in case of any weird problems that persist.
How I personally fixed this:
In the identity inspector in User Defined Runtime Attributes I noticed that I had an old IB_Inspectable element that I had deleted from my code, but it was still in there. Removing it with the - button got rid of this error.
Try changing your "CGFloat" declaration for spacingBetweenLabelAndImage into "NSNumber".
As far as I know, you can't call "setValue:" on a C-type variable.
Changing the declaration of "spacingBetwenLabelAndImage" to NSNumber would also require you to change a bit of code too:
CGFloat halfSpacing = self.spacingBetweenLabelAndImage == 0 ? 0 : self.spacingBetweenLabelAndImage / 2;
might become something like:
CGFloat halfSpacing = (self.spacingBetweenLabelAndImage ? ([self.spacingBetweenLabelAndImage floatValue] / 2) : 0.0);
(I'm not 100% certain if this is a perfect translation of the first line, but I wanted to show how to get a floatValue out of a NSNumber)
I had a similar problem, but I actually removed the property from the class and Interface Builder was still complaining about the missing property, tough.
Tried many things, like cleaning, rebuilding... But nothing worked!
What really solved was right clicking in the Storyboard file, selecting "Open As" and then "Source code". This opened the storyboard XML content in the editor and I was able to look for references to the missing property until I found the section:
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute... keyPath="My Missing Property Name">
...
</userDefinedRuntimeAttributes>
After removing the whole section, I saved the file and refreshed the view in Interface Builder. Now all warnings are gone!
I used the method Departamento B provided but it didn't really work. However, I fixed my problem by
1. Selecting the buggy views from story board
2. Clicking (Editor - Debug selected view)
Hope this helps
If you are sure that you set all the setters right, and if you imported some other SDKs in your project and you are getting this issue,
check 'Linked Frameworks and Libraries' in Target - General.
After I correctly linked some SDK frameworks, the error went away.
I had this error, when has two targets. One with my main project and other with target, where i hold designable classes (for faster build).
The issue was that in storyboard there were missing a Module.

Xcode 6: can't connect any IBOutlet to ViewController

After upgrading to Xcode 6, I opened an old project (that contains a subproject, so it has many targets)
and I noticed that no link from my Storyboard ViewContoller to the relative Objects works.
For example I have a ViewController with a TableView inside and now I cant do can't do anyhing with it because the connection is missing, I can't even redefine a new IBOutlet in the VC because the arrow in the storyboard from the VC won't connect to anything.
To be more clear:
The class is defined in the Custom Class section, so I can't find the problem
What should I do?
Btw I'm using obj-c not swift, I found some related answer but all about swift.
You can also see that the link between the parent view and the custom class is broken (not visible anymore) which is a huge problem.
I had the exact same issue with the app i'm working on actually, updating XCode from 5.xxx to 6.1. The workaround that worked for me was to remove the reference of every view controller and re-add them to the project...
To everyone facing that issue, here's the (annoying) trick :
Step 1 : select both .h and .m view controller files
Step 2 : remove the reference of those files
Step 3 : re-add the files to your project tree
Step 4 : open the storyboard, eventually re-build the project and smile
I can understand those things could be reaaally annoying, but it worked for me... Hope it will help someone else !
In your storyboard hierarchy select the View Controller,
In the right pane Custom Class section Class, select the drop down and your desired view controller.
I've experienced similar behaviour in Xcode 6.1.1 when trying to add the first outlet to a new view.
Tried removing the references and adding the files again as suggested above with no success.
What I did find worked was writing the first property on the new view by hand. I just popped in:
#property NSString *temp;
I could then attach my outlets in the normal way. Just delete the temporary property once you've added your first outlet.
Hope this helps.
It seems typing the outlet first (swift):
#IBOutlet weak var someViewOutlet: UIView!
and then dragging from IB the outlet to the far right type in the above code works.
Restarting Xcode resolves the issue (sometimes). Using Xcode 6.1
Maybe I can help
In my case the problem was that the viewController.swift file was not connected to the StoryBoard. The solution is to click in the Upper border of the view on the storyboard beside the 3 icons (View Controller, First Responder and Exit)...now look over in the Utility Area choose Identity Inspector, and in "Custom Class" choose the custom view controller.
Hope this helps. Xcode is hard!!
Here's the proper solution i believe.
If you renamed the controller in code, you need to update the .xib file.
I could not find a way to do it in the interface builder, so do this:
Open the .xib file with a text editor: right click the file > open as > source code
In the <objects> node find the <placeholder> node with the property placeholderIdentifier="IBFilesOwner" and replace the value in customClass="MyOldControllerName" with your new controller name: customClass="MyNewControllerName"
And all your IBOutlets will work as normal again.
Thanks to everyone who commented.
It is a bug of Xcode 6 / 6.0.1. Downloaded and installed the 6.1 version and the problem disappeared.
Maybe try to delete the outlet from the menu in the storyboard (in your screenshot) and drag it again of the element.
Okay, let's check iff it is the lack of a module name.
In your storyboard ViewController, type in the name of module. (the project name)
2.Clcick outside in another field. When you go back to the module field it may say none, but now there will be a dropdown menu entry for your project name.
Select your project name and see if everything is good.
If there are still issues I will post photos.
Seems to be a workspace issue. Try to remove project form a workspace and add it again. It helped in my case.
I had this, affected all projects on my machine, swift and objective c and drove me mad for ages. Finally also noticed that I could not use the refractor to rename classes either.
The fix for me was:
Close xcode
Delete ~/Library/Developer/Xcode/DerivedData (just doing this on its own did not work!!)
Delete all user data for all my projects using the following from the directory that contains all my projects e.g. /src (be careful with this command!):
find . -name 'xcuserdata' -exec rm -rf {} \;
If you want to do it by hand just do the following for all your projects
Delete .xcodeproj/project.xcworkspace/xcuserdata
Delete .xcodeproj/xcuserdata/.xcuserdatad
Get Spotlight to re-index the drive all my projects were on (not sure if this was required
Re-boot machine
Everything sprang back into life !
I was having this same issue.
It turns out I renamed my view controller class and file name. In storyboard, I had the stale value in the right pane, Custom Class -> Class. So the IBOutlets were not aligning because there were none in the missing class, which is where it was expecting to find the defined outlets.
Filling in the correct class name of the View Controller in the Custom Class field in the right pane fixed my issue.
XCode needs to be more verbose if you have a bad class name in the Custom Class fields.
no one solution fixed my same problem...
But i have solved by:
close xcode
renaming the folder of the project
open xcode
and then the outlets will be back again
I hope that this solution is the right one for the people who have the same problem
In Xcode 6.3 I needed to close Xcode and restart the Mac. Restarting Xcode alone didn't do it for me.
I've had 6.3 for a long time and my problem was with new projects I was creating to test some things. Definitely not an upgrade issue this time.
I have Xcode 6.3 and saw similar issue. Finally few edits in .h file resolved my issue. If your interface has IBOutlet defined as
#interface NavigationViewController :UIViewController
{
IBOutlet UILabel *lblName;
}
change this to and in .m file add #synthesize lblName;
#interface NavigationViewController :UIViewController
{
__weak UILabel *lblName;
}
#property (nonatomic, weak) IBOutlet UILabel *lblName;
I was having this same problem, with no view outlet available to link to. The only way I was able to fix it was to change the owner class of the XIB file to "UIViewController," make the link, and then change it back to my intended custom view controller class. The link stayed and all was well.

Interface builder and subclass of UITextView

I'm using XCode 4.6 and I'm trying to replace one of my UITextView's by a SSTextView from SSToolKit in order to add a placeholder to it. The SSToolkit library is correctly integrated in my project thanks to CocoaPods. So I just changed the type of the property in my view controller to be SSTextView instead of UITextView:
#property (strong, nonatomic) IBOutlet SSTextView *commentTextView;
And of course I also changed the class of the control in interface builder's inspector:
And yet, in my controller's viewWillAppear: the property is still a UITextView and when I set the placeholder:
self.commentTextView.placeholder = NSLocalizedString(#"Comment", #"");
I get an "unrecognizable selector setPlaceholder: sent to instance".
It seems to me like I've done that sort of things a thousand times and yet here, I can't figure out what I'm forgetting.
I figured it out. It turns out some parts of the compiled application seem not to be overwritten when redeploying to the simulator. So after I deleted the app from the simulator and ran it from scratch, it worked normally. I had other bugs like missing segues and so on so I looked that up and found out about the "delete app" technique. Weird...

Resources