Swift PNChart PNCircleChart with Storyboard - ios

I'm trying to set up a basic PNChart PNCircleChart on my app. I created a UIView in the storyboard and set the class to PNCircleChart. The restoration ID is piechart. I created an outlet in to my view controller that looks like:
#IBOutlet weak var pie: PNCircleChart!
Now I'm trying to build a basic piechart in my viewdidload and I can't figure out how.
pie.backgroundColor = UIColor.greenColor()
pie.setValue(50, forKey: "A")
pie.setValue(50, forKey: "B")
pie.strokeChart()
It is failing with a NSUnkownKeyException error. Any idea how to do this in swift

The NSUnknownKeyException is almost always caused when one of your interface elements was hooked up to a property in your view controller that you then deleted. The property was deleted from the view controller, but the interface builder was never unhooked from that property.
The actual exception message should tell you what "key" it's having trouble finding, which should give you a hint as to which UI element is hooked up wrong.
Once you figure out which key is hooked up wrong, go through your UI elements and right click on each of them. One of them will be hooked up to a property of this name (and it won't exist in your class source code file). You need to either click the X for this connection to delete the connection, or you need to add the property back to your source code file.

Related

Exposing UIElements to the ViewController

I am using Xcode 9.1 and trying to build a program. I have designed one textbook , one label and one button. Now I am trying to place the textbook in view controller to code it, But Unable to do this.
In your view controller, you want to setup an outlet. Add a property like
#IBOutlet var textField: UITextField?
In the interface you have screenshot, a small circle should then appear next to it, which you want to drag over to connect to your text field. This creates a binding between the property in your controller and the view element.
You can then reference this property in your controller to access the text field.

How do I add a VIMVideoPlayerView to my view controller?

Maybe I'm just going about this the wrong way, but I'm trying to figure out how to add a VIMVideoPlayerView to my view controller through storyboard.
The documentation says "Create a new VIMVideoPlayerView instance or set up an #IBOutlet:" which as far as I understand means that I should be able to add it through the interface builder. But this object does not appear in the object library.
I'm pretty new to this, so I'm trying to figure out how to add a submodule object into my storyboard. I added VIMVideoPlayer using CocoaPods.
If this actually isn't possible, what is the proper way to setup a VIMVideoPlayer programically?
Drag a view from object list and change set it class to VIMVideoPlayerView. Then you will be able to create IBOutlet for this Enter VIMVideo class name under class
I have not worked with Vimeo library but you need to drag and drop a UIView on the storyboard and set the class of this UIView to VIMVideoPlayerView

Hide Outlets from Connections Inspector for Custom View

I have created a custom view (Quantity View) with nib file in Swift. I have created some IBOutlets & IBActions (for buttons, labels etc.) in my custom view.
I tried to use this custom view (Quantity View) by assigning class name to a UIView in my storyboard.
It's showing me all the IBOutlets & IBActions in the Connections Inspector, as shown in this screenshot: .
I just want to show only delegate for the Custom view.
Possible Answer:
I thought I can use the -viewWithTag to get the views instead of Outlets.
But, I want to know if it's possible with having Outlets also or if there is much better way to do this?
What are the other possible ways (optimum) to handle this situation?
You can also consider the following solution:
You can take the subviews of your QuantityViews(custom view) and you can identify the specific views by its frame origin.
Note : you should know the customview subviews frame
Its not possible to hide IBOutlets from storyboard if you declare the class members as IBs (IBOutlets or IBActions).
The IBOutlets or the IBActions are just indicators to the interface builder so that it can show the names on it when you try to bind them it actually calls the setValue: forKey: method to set the view's reference to the IBOutlet property.
Now if you try to access an subview from the file's owner class without any IBoutlets you need to have a pointer to point it, so for that either you can get the reference using ObjectID which is assigned to the subview by the interface builder or you can get it using the viewWithTag: method.
The ObjectID you need to find all time when you add or replace a subview from the view, so better and convenient approach is to use tag property of UIView class.
So my conclusion to this problem is to access the views using the viewWithTag method you mentioned earlier.
I think your way is correct. But sometimes Xcode doesn't work correctly.
The following makes the IBOutlets and IBActions reappear and work properly:
Clean project your project in Xcode.
Quit Xcode completely.
Delete all contents of ~/Library/Developer/Xcode/DerivedData/.
Restart MacOS just in case.
I hope you will resolve that :)

Can't link a bar button to an #IBAction in superclass

I have a number of view controllers, each with their own menu button (a UIBarButton, added in the storyboard). Now I want to link all these up to a single #IBAction function in their superclass (the superclass is the same for all the view controllers with that menubutton).
Now I have linked up #IBOutlets to a superclass before, but it doesn't seem to work with #IBActions, even though the function isn't private, and it definitely is part of the superclass (I am refactoring, previously it was an #IBAction in each class, which only did menuButtonTap() (calling the method in the superclass).
Any ideas?
I have solved the problem by manually creating an #IBAction on the superclass, and giving them the same name as the ones I create in the subclasses. Then I deleted the ones in the subclasses. This leaves a 'dangling reference' from the storyboard, according to Xcode, but I know it's there.
Although this still does not work as of Xcode 9.4 for general purpose UIViewController (but your workaround still does work 👍🏻), please note that it works as expected for UITableViewCell templates in storyboard.
If some of your template cells in storyboard share the same base class containing #IBOutlet properties, you will be able to link them to every template cell instance as you usually do:
Then Xcode will show a popup for telling in which prototype cell the link is "backed":
I'm not sure why this second step is necessary though, since you designate a specific component from within a given prototype cell
You can do it like you do when adding an action to a UITabbar button from subview class.
Assuming btn is a UIBarButtonItem,
[btn setTarget:self.superview];
[btn setAction:#selector(menuButtonTap:)]
Are you using __unused keyword by any chance? If you do the IBAction won't show up in storyboard(I am using Xcode 6.3.2)
- (IBAction)actionBack:(__unused id)sender;
vs
- (IBAction)actionBack:(id)sender;
To make it show up and selectable removed the __unsused keyword.

Can't add a new view in a storyboard without getting an not key value compliant message

I'm getting the "not key-value coding compliant message".
I've had this several times in the past and know what it means and have always been able to resolve it, but I don't know why I'm getting it in this instance. All I've done is:
1) drag n drop a UILabel onto the main view:
2) Drag from the UILabel to view controller and get IB to insert and connect an outlet:
But when I run I get "this class is not key value coding-compliant for the key currentStatus.'"
Here's the connections:
Why is it not working, what is missing?
What you have shown is ok, check if you removed some outlet properties from your code file (.h) and forgot to remove their links from IB.

Resources