unable to create outlet in xamarin for imageview.App crashes - xamarin

i have used an imageview in the ios builder in visual studio whose refrence is automatically connected to my viewcontroller class and when i do set image to that imageview my app crashes with an error "This class is not key-value complient for the key image__"
As i am new to xamarin i am not aware if we need to do anything else inorder to make relation from storyboard to the class variable for access that particular outlet object.Please suggest me if you have any advice?

Open the storyboard in visual studio and then open properties pad. Select the image view and give Name in the identity option. Outlets from Xcode did not work in xamarin.
For example, your view controller name is TestView and you give the Name to image view as MyImage. Now there is one more file named TestView.designer.cs open that file and you will see that Outlets are generated in that file.

You might have accidentally removed the connection.
Is your imageView name: image__?
Given if the imageView is in ViewController.cs, look at the Solution Explorer, expand and find the ViewController.designer.cs and remove the imageView or image__(in your case) Outlet and whatever that's related to it and then re-link the Outlet again.

The problem was that the refrence was not working properly. I just removed the image outlet and viewController class and closed the project.Then i started creating that same class from very scratch and created the outlet from the storyboard. That was it. Everything started working COOL..!!!
I hope restarting the project helped me and it can help you too.Good Luck.

Related

How generate ViewController.h file in Xcode?

I create a new ViewController and renamed class. But still, the .h file where I want to store outlets and action doesn't appear.
In your xib or storyboard file change the Class in File's Owner to mach the one you had renamed.
See image:
When you add a new view controller and you think files *your controller name*.h and *your controller name*.m should automatically create. In my case, I start building a project(not in Visual Studio) in XCode. And after that, my files appear.

IBOutlet connect fails to connect to renamed target

So, I was following along a core-data tutorial RayWenderlich.com part 1/3 circa 2012 using Xcode 8. Naturally some things are different now, like the default view controller and storyboards vs xib being used.
So rather than explicitly creating a xib for the MasterViewController, etc. (I instead did things the Xcode 8 way), I just renamed the supplied ViewController, and the associated .h and .m contents to MasterViewController. All was fine until I got to the step to add its outlet in the app delegate.
No joy.
Snippet shows the outlet is there but I cannot link to it.
I uploaded the project to ScaryBugsMac on github as I'm stuck what's wrong. Tried suggestions on similar question to remove/add, import vs include for the header, and to publish the outlet by putting it in the app delegate header.
I'm thinking the rename isn't being handled but I want to know how it's broken and how to fix it.
Well I punted and restarted, this time without renaming the controller. Find "part 1" of the tutorial in ScaryBug on github.

Xcode drag and drop ViewController from one project to another

It happens that the IBOutlets in the new project are connecting to the storyboard of the original project? How to avoid? Or how to disconnect from the ViewController code?
Here you can see MainStoryboard_iphone is storyboard in original project, Main_iPhone_storyboard is storyboard in the new project.
Thanks.
I would suggest a simple hack if you don't have a lot of classes - create new files for every header file where you declare your IBOutlets and copy over the code - it might as well solve the problem.

Can't hook up IBOutlet or IBAction to a View Controller written in Swift after deleting the ObjC version

I created a project in XCode 5 and imported it to XCode 6 beta, then later decided that I wanted to rewrite one of the ViewControllers in Swift. So I first deleted the controller file (both .h & .m) and added the same class named controller within a Swift file extension. Now when I try to hook up an outlet and action from the Storyboard by ctrl-dragging from the widget to the file, I can't create new connections.
Is this a bug or do I need to do something else to get it to work?
Seems to be bug in Xcode 6. You can resolve this by Changing the ViewController Custom class in the identity inspector to some another class press return and again change the class to original class you want then press return.

How to get your custom content drawn in Interface Builder?

I watched the "What's New in Interface Builder" session video and tried to replicate the code that was showed but unfortunately when I assign a view to my custom class which has #IBDesignable I get 2 errors:
Main.storyboard: error: Live Views: Failed to update auto layout status: The bundle “swiftTest” couldn’t be loaded because its executable isn’t loadable.
Main.storyboard: error: Live Views: Failed to render instance of _TtC9swiftTest14ControllerView: The bundle “swiftTest” couldn’t be loaded because its executable isn’t loadable.
Later on in the video I saw that to have Live Views you have to make these steps:
1. Create framework
2. Create class
3. Mark as designable
How do I make the 1st step?
Thanks
As I understand it at the moment (prior to Xcode 6 Beta 3), #IBDesignable will only work from a view declared in a separate framework target.
However, I also struggled to add it because I had no "plus" button as described in various links (because the Hide Project & Target Lists arrow option was toggled off).
So, select your current project target, then just use the xcode menu options:
Editor > Add target...
Then select
Framework & Library > Cocoa Touch Framework etc.
By the way, to test #IBDesignable, this tutorial worked perfectly as a starting point:
http://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/
One small but important thing to note in that tutorial (if you follow it onscreen instead of following on to its full github code listing) is that your view class must be prepended/decorated with #IBDesignable, e.g.
class CustomView : UIView {...}
should be
#IBDesignable class CustomView : UIView {...}
You should make new framework as a target for current project and add your live views in this framework. On General tab on main target you will see your framework in Embedded Binaries section.
I had a project with live views working and at one point I also had these error messages. This went away for me when closing XCode and restarting, fwiw.
It is working very well (and easily) for me with Swift in Xcode 6 Beta 5.
I've confirmed that with Xcode 6 Beta 5 I did not need to add any frameworks (for example, Cocoa Touch framework option under frameworks in the dialog that appears when adding a new project target). Nor did I need to add IBDesignable.h to the project. Both seem to be outdated requirements as per the the weheartswift.com write-up linked in the initial answer to the question.
All I needed to do was:
Prefix class definition of my custom Swift class source file
with keyword #IBDesignable
Prefix vars I wanted to show up in IB Attributes Inspector with #IBInspectable (IB recognizes several common variable types).
Then, after assigning my custom component's (UIControl subclass) name to IB's "Class" name file (under Identity Inspector tab, in right pane) replacing "UIView" -- e.g. the class name of the UIView placeholder object I originally dragged onto the IB VC's view -- upon selecting my custom component from the Content View component list in IB, I saw all my custom class' inspectable items show up in the IB Attributes Inspector!! Very cool.
Note: At first XCode would only allow me to prefix one variable with #IBInspectable. It showed errors on subsequent ones. Then, suddenly it seemed to work, and no more problems after that. Not sure if it was a typo or just took Xcode awhile to re-index my project and pre-compile or parse the code.
I code about #IBDesignable & #IBInspectable,
firstly, I got two errors like you,
then, I change the code I wrote,
you can checkout the code from my github
Good Luck.

Resources