IBDesignable Not Working Xcode 7 Swift 2 (core graphics) - ios

The IBDesignable property seems to be not working on Xcode 7 using swift 2. Below is my custom class to draw a button.
#IBDesignable class PushButtonView: UIButton {
override func drawRect(rect: CGRect) {
let path = UIBezierPath(ovalInRect: rect)
UIColor.greenColor().setFill()
path.fill()
}
the code is running in the simulator. (See image 1) I have also attached a screenshot of the storyboard (see image 2) Not sure if some settings need to be changed

I had the same issue with "Mixpanel" CocoaPod.
You can check if everything is compiling for the interface builder in the Report Navigator (Left pane, the right-most tab). Click on "By Group" to filter content and look at the "Interface Builder" section. You will see there if something went wrong while compiling with the ibtool. In my case mixpanel survey widget was not compiling.
I simply removed the pod from the podfile, did pod install and could work on my custom view. Once done with the custom view i added mixpanel to the podfile again. Hope this helps

Click Editor > Refresh All Views after you make the changes.
Alternatively, you can also select Editor > Automatically Refresh Views, but I find that sometimes buggy and may not consistently.

Related

Interface Builder can't set accessibility traits (Xcode 8)

I am having a weird problem in Interface Builder (Xcode 8). Basically, I can't enable (select) accessibility traits; IB is rejecting my attempt.
For example, I have a UILabel which has the "static text" and "user interaction enabled" traits enabled. I can click the "static text" checkbox to disable it. But then when I click it again to re-enable it, the checkbox briefly shows a minus ("-") which then disappears, leaving the checkbox unchecked.
I don't know how to re-enable that checkbox (or any other). Any solutions would be appreciated!
This has happened to me once. Try restarting Xcode.
This was a bug introduced in Xcode 8, that affected inspector properties that map to bit mask properties. This includes iOS accessibility attributes, NSWindow style masks, and popover segue directions.
https://twitter.com/eternalstorms/status/776384102291431424
It's fixed in Xcode 8.3.
I still find the bug in xcode 8 (do they even fix them?) and when i restart xcode i'm able to set one or two of these traits, then the bug reappear...
One way to deal with it is to edit the file "as source code":
in the Project navigator panel right click on the xib file and "Open as -> Source code"
find the block "

Xcode 8 - IB Designables - Failed to render and update auto layout status, The agent crashed

I recently upgraded to Xcode 8 and I am having issues with the Storyboard.
If I open the project and I don't have the Storyboard open, it will compile and run just fine. Once I open up the Storyboard, I get multiple errors about IB Designables as shown below.
These views are the only views that are using custom views from TextFieldEffects and BEMCheckbox that I imported using Cocoapods.
You can try one of the following to figure out the cause:
look for the IBDesignablesAgentCocoaTouch logs in this directory:
~/Library/Logs/DiagnosticReports and see the cause.
Note: for user with Catalina: look for
IBDesignablesAgent-iOS_<DATE>-<MAC_NAME>.crash
Go to the Editor -> Debug Selected View while selecting your #IBDesignable UIView in your storyboard, and see the stack trace.
Delete Derive Data folder.
Xcode Preference -> Location -> Derived Data
/Users/YourMacName/Library/Developer/Xcode/DerivedData
Clean your project Shift + Command + Alt + K.
Build your project Command + B.
I solved the problem by doing the following:
Go to File > Workspace settings.
Click the little right arrow beside "Derived data". This opens the Finder app at the location of the DerivedData folder.
Go inside the DerivedData folder, and delete the folder corresponding to your project.
Quit Xcode, and re-open it.
Clean your project shiftcommandk.
build your project commandb.
Open your storyboard.
Go to Editor > Refresh all views.
Updated
Sometimes just directly Go to Editor > Refresh all views worked. If Refresh all views is disabled, quit Xcode and try again.
I just delete the view that is failed and press command+Z to undo deletion. It works for me.
If editing the failed view later, the error may occur again, do the above again.
I faced this issue in CocoaPod 1.5.0. The solution is to reinstall pod again (pod install again) once this error showing or you may use CocoaPod 1.4.0 instead. It works fine in 1.4.0 (at least for me.)
update:
Add following script in Podfile help me solve the issue in 1.5.0
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
config.build_settings.delete('CODE_SIGNING_ALLOWED')
config.build_settings.delete('CODE_SIGNING_REQUIRED')
end
end
reference: https://github.com/Skyscanner/SkyFloatingLabelTextField/issues/201#issuecomment-381915911
Adding following code to my #IBDesignable class did the trick.
override init(frame: CGRect) {
super.init(frame: frame)
}
If you're using xib file for custom uiview. Try this:
Change from
Bundle.main.loadNibNamed("UserView", owner: self, options: nil)
To:
let bundle = Bundle(for: UserView.self)
bundle.loadNibNamed("UserView", owner: self, options: nil)
For anyone -like me- who can't find that IBDesignablesAgentCocoaTouch file or when trying to 'Debug Selected Views' from the Editor gets an error, here's another way to debug those "Failed to render" errors.
Open the 'Console' app, from the sidebar select your current Mac (it will probably be auto-selected by default) and then on the search bar search for "IBSceneUpdate" and hit enter.
This way, every time you get an Xcode error for an IBDesignable not being able to render, you will also get a new "IBSceneUpdate" entry with more details about the error.
That's at least how I was able to debug my IBDesignable errors!
Try to disable 'Use Trait Variations' (Identity and Type panel) for any xib file that you might have for custom views that are used in your storyboard.
Correct answer provided by #Maria:
check crash report at ~/Library/Logs/DiagnosticReports
Alternative way:
Open Spotlight
Type console.app
Select Crash reports
Check one for IBDesignablesAgent-iOS and review crash log
My problem was solved by deleting folders (which is related to this project) from the derived data folder.
You can do this by:
Clicking menu File → Project Setting
Click the arrow sign deside /Users/.../Xcode/DerivedData.
Click the DerivedData folder. You will see your project named folders. Delete those.
Quit Xcode and then open your project.
Clean the project by using this step: Product → Clean.
Then build the project: Product → Build
These will resolve these problems.
I tried clean and run the project won't solve this issue.
But Close and reopened the project did.
Just open your storyboard -> Editor -> Refresh all views.
This work for me.
I had the same issue and came here to try and figure out what happened. I noticed the top rated answer and the answer itself didn't help me, as IBDesignable didn't exist in the log folder and I already attempted all other options there, however in the comments I noticed someone talking about a frame init.
I decided to try commenting out my IBDesignable extension for UIView and it instantly fixed the problem. So, to fix this, find the extension causing the issue and make sure to set up the required inits by creating an IBDesignable class and providing the required initializers as follows:
#IBDesignable class RoundedView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
sharedInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
sharedInit()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
sharedInit()
}
func sharedInit() {
}
}
IMPORTANT: remember to add the new class to the item you are using the designable on.
When I debugged this, I found out there are some classes which are modifying the UI. Typically marquelabel which is a subclass of UILabel or any other class subclassing UIView and drawing UI at run time and colliding with Autolayout engine. Try giving a fixed width or height for these custom views. If it doesn't solve your problem try the following solutions:
Solution 1: Uncomment #use_frameworks inside your pod file.
Solution 2: Try deleting derived data
Close the Editor window of your Xcode and quit the simulator
Go to Xcode Preferences → Locations
Click the small grey arrow showing the derived data path
Select your project
Delete all the folders inside
Quit Xcode and reopen
In my #IBDesignable class crashed because I used the custom class for the color and forced unwrapped the colours propertied that's #IBDesignable class found nil while unwrap
So you need to find the IBDesignablesAgent-iOS_[Date]_[YourMac].crash on ~/Library/Logs/DiagnosticReports this location and you will get the reason of the crash with the respected file path.
Now you have to check the respected file.
Faced same Error:
Had customised UITextField and using interface builder, the error in console was
-Use of unimplemented initializer 'init(frame:)' for class "CustomField"
Added the initialiser to fix the error
I faced this problem after update to latest XCode version .After trying multiple solution described above ,i only quite Xcode and then shut down system and turn it on and that worked for me .
In my case, I faced this problem because I was using a class that generated that error. Just stop using that and the problem will be solved!
This was the class I was using. I changed for UIView and then the error disappeared:
After you make the necessary changes, change the storyboard or in my case a .xib to open in "XCode 7", save and close. This is just a stop gap measure to address the errors but ultimately you will need to fix them or do this until you are no longer able to.
In my case, I was using a library which was subclassing UIView. It was using IB_DESIGNABLE, and was missing call to [super awakeFromNib]. Once I've added the call to this method, the bug went away.
I'm not sure if the fact that it was implementing IB_DESIGNABLE had an impact in this.
This is the easiest way for me: add this script to your Podfile
Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
next if target.product_type == "com.apple.product-type.bundle"
target.build_configurations.each do |config|
config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR'
end
end
end
Source:
This workaround for #IBDesignable can be found here: https://github.com/CocoaPods/CocoaPods/issues/5334
For me it was due to incorrect Font Name in Storyboard. Correcting the font name fixed the issue.
Discarding the below change fixed the issue.
My first try of exiting Xcode and relaunching helped.
So it is some easy quick-fix instead of some work ,-)

Weird animations when changing NavigationItem prompt

I have these ViewControllers added in storyboard:
None is connected with a custom class, everything is from pure storyboard.
Video on iPhone simulator on iOS7
This only happens when using AutoLayout on iOS7.
Anyone else seen this?
Download sample project of problem
I think this problem occurs when view is getting autolayout and setting it size to main screen size. In iOS 7 navigation push animation come before view size is set so we can see that animating. Don't worry it works well in iOS 8.0 and later. For iOS 7.0 you can give size of view in viewDidLoad so it can adjust size before it appears.
Edit 2:
As someone mentionned in the comments, I am unable to reproduce the problem with your sample project. One thing I noticed though, is that your project is configured with a deployment target that is iOS 8.3. Here are the steps to fix that :
Step 1: Select your project in Xcode's Project Navigator.
Step 2: Make sure you select your project in the left column of the project editor and not the target
Step 3: Select the Build Settings tab
Step 4: Modify the iOS Deployment Target to iOS 7.1 or iOS 7.0 depending on which OS you are testing with.
Step 5: Build and run.
Hopefully this will help you out.
Edit:
Step1. Select your UIViewController with the label 14 and in the third tab of the right pane of Xcode, enter a Storyboard ID such as vc14.
Step2. Select your UIViewController with the label 12 and in the same tab, enter a custom class such as ViewController.
Step3. Remove the trigger segue action from your Button and replace it by a #IBAction in ViewController
Step4. Add this code to your #IBAction in ViewController :
#IBAction func push(sender: AnyObject) {
var vc14 = self.storyboard?.instantiateViewControllerWithIdentifier("vc14") as! UIViewController
vc14.view.layoutIfNeeded()
self.navigationController?.pushViewController(vc14, animated: true)
}
Explanation:
The weird animation is occurring because layout has never occurred before the segue pushes the UIViewController in the UINavigationController. iOS 7 didn't protect appropriately against such a scenario by manually calling layoutIfNeeded before entering an animation block and when the layout finally occurs, it triggers implicit animations. In the code sample I have given you, I manually trigger layout before pushing the ViewController on the stack in order to avoid this issue.
i think you Press ⌘T. so the Slow animation is start. Check the all Simulator you Use.
Debug->Slow Animation
I attach Image check it.

Why does my Xcode 5 doesn't autocomplete nothing?

I'm starting a project but I have another one very similar as base.
I create my new project with storyboard and CoreData, create a new file of NSObject class, and when I start writing in the .h file:
#property (nonanatomic, retain) ns...
nsstring or any type of variable doesn't appear... for example, I start writing ns and it appears:
NS_DURING
NS_ENDHANDLER
NS_HANDLER
NS_VALUERETURN
NS_VOIDRETURN
and the most of code is in black letter, i mean, nothing is coloured as it shoud be normal like purple, blue, etc... the colour that xcode sets... here you can see it:
http://oi61.tinypic.com/359iws6.jpg
P.S: I'm using Xcode 5 Preview 3 and OsX Mavericks. I've never had this problem I think.
Possibly your dot-m (the implementation) file is not a member of the target.
When adding a new file to the project on the bottom of the save dialog there is a Target Membership window . Did you check that box?
To view the target membership and/or to add an existing file to your target open the implementation file. Then open the File Inspector using ⌥+⌘ 1 or View, Utilities, Show File Inspector.
In the File Inspector window halfway down there is the Target Membership. Check the box next to your target.
Syntax highlighting will begin after a short moment, wait for Xcode to finish its indexing.
Try out this: In XCode open Preferences, click on the Text Editing Tab and make sure "Use Escape key to show completion suggestions" is checked.

xCode crashes when I drag custom object into UIScrollView

I have a custom button that is a subclassed UIButton. When I try to drag it into a UIScrollView in IB Xcode immediately crashes. What gives?
I have this custom button working inside a UIScrollView in at least one other location in my app. Any ideas?
UPDATE:
Uncheck "Use Autolayout" in the File Inspector fixes this problem. See answer below.
I have this custom button working inside a UIScrollView in at least
one other location in my app. Any ideas?
I could crash several Java editor like this. The problem it was in my custom component code:
I have added code, which the designer ( Interface builder) have executed to show my component.
Take extra care at init, viewDidLoad methods in your Button code.
Do not know exactly, But once the same kind of issue happened with me.
My problem was that some of my drawing methods were being called recursively, causing the Xcode to crash. I handled those recursive calls and issue got fixed.
SOLUTION: Uncheck "Use Autolayout" in the File Inspector
Thanks to #BornCoder I decided to try running this on my laptop running Xcode 4.4. When I tried to build I got an error saying this version of Xcode doesn't support Autolayout. I didn't intend to use Autolayout, it looks like Xcode 4.5 does automatically. Unchecking the box fixed it.

Resources