So I have started to play around with MonoTouch.
OS X 10.6.8
MonoTouch v4.0.3
MonoDevelop v2.4.2
Mono Framework v2.10.2
XCode v3.2.6
So I'm having problems with the outlets. Creating a simple one page program, editing the XIB in Interface Builder to add outlets, they are properly inserted as class properties into the MainWindow.xib.designer.cs like so:
[MonoTouch.Foundation.Connect("btnClickMe")]
private MonoTouch.UIKit.UIButton btnClickMe {
get {
this.__mt_btnClickMe = ((MonoTouch.UIKit.UIButton)(this.GetNativeField("btnClickMe")));
return this.__mt_btnClickMe;
}
set {
this.__mt_btnClickMe = value;
this.SetNativeField("btnClickMe", value);
}
}
However, when I create a multi page navigation based project in MonoDevelop and create outlets for my Views, they are not inserted into the *.designer.xib.cs files.
This is probably some noob beginner mistake, but what could I be doing wrong?
Well, after fiddling around, I found out the issue.
I added my outlets in the View class in the Library Windows.
The correct place to add them is in the File's Owner class.
#Dimitris, add your comment as an answer, and I can accept it as an answer.
Related
Autocomplete isn't working for me when accessing members from a class extension in Xcode (6.3.2).
I made a UIColor extension, and I am accessing them via UIColor().sampleExtendedColorName(), and it does not show up while I'm typing. Autocomplete works for everything other than this. Is there a setting I can change?
extension UIColor{
func sampleExtendedColorName() -> UIColor {
return UIColor(red:200/255, green:100/255, blue:120/255, alpha:1.0)
}
}
Update (new info):
So autocomplete is working if I access the UIColors from a ViewController that directly subclasses UIViewController, but if I subclass a custom CustomViewController that is a subclass of UIViewController, autocomplete doesn't show up for some reason.
Checking all the Target Memberships is working fine. If you don't know where the Target Membership is,
Go to your swift file (Eg: ViewController.swift)
On the right side in the Utilities panel, Click file inspector
You can see Target Membership there.
Check all the fields.
Figured it out, issue was on my ColorExtension.Swift file in my Xcode project. I needed to check all the Target Memberships.
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.
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.
I am trying to build a custom TableViewCell, and so far I have created a xib file and laid it out in XCode designer. However, I cannot find my class in the drop down in identity inspector, and I cannot locate the generated class when in content assister.
Is there something beyond creating the xib in MonoDev to make my designer class available to XCode designer?
The (C#) class needs to have a Register attribute:
[Register ("MyClass")]
public class MyClass : UITableViewCell
{
}
Per Xamarin support:
When creating a custom UITableViewCell (and wanting to use the
designer), you have to use a bit of a "hacky" process to get the
code-behind file to work. You are going to want to add the class as a
iPhone (or iPad or Universal) UIViewController, change the superclass
of the class you just created to UITableViewCell. Make your changes in
the Xcode designer (delete view and add UITableViewCell), and then
make your changes in your code-behind file.
There is a great tutorial on how to do this here:
http://www.arcticmill.com/2012/05/uitableview-with-custom-uitableviewcell.html
I was used to creating Custom Cells in MonoTouch using Interface Builder but ever since XCode 4 has this integrated I can't seem to get it to work.
Is this a know issue?
Does anyone know of an article that describes how to go about this? I have plenty of books and found articles about how this works in XCode 3 (Interface Builder) but I am looking at how this works in XCode 4 !!
Also, when creating iPad View Controllers in MonoTouch the files seem to be separated (I get an fHeader.cs and a fHeader.xib file) whereas before the fHeader.cs file was 'part of' the xib file (hierarchically below it). Why is this?
I am using Mono 2.10.9 - XCode 4.2 and Monotouch 5.2.11
Thanks
This has a nice tutorial:
http://blog.arcticmill.com/2012/05/uitableview-with-custom-uitableviewcell.html
Check this tutorial:
http://sabonrai.wordpress.com/2009/08/28/monotouch-sample-code-uitableview/
Normally you create a DataSource Delegate and there you override the GetCell function.
In this function you can create your custom cell.