Why can't I access my application delegate from a ViewController? - swift

In my app, I would like to access delegate methods from a View Controller, but when I try to access it this way :
let appDelegate = NSApplication.sharedApplication().delegate
I am getting nil, what could cause this ?
EDIT WITH ADDITIONAL INFO :
When I created the app, I did an error as I didn't choose to use storyboards, but when I needed them, I just added a storyboard file and defined it as the main interface, like this :
I believe my issue could come from here, could it be possible for the interface to be shown but not linked properly to the NSApplication (and so to the delegate) ?
If yes, how could I solve it ?
Thank you.

In your storyboard, make sure that App Delegate's custom class (in the Identity Inspector) is set to your delegate class.
Update
If you have just created a new storyboard, it will be empty. AFAIK there are no "standard" ways of creating the application scene. You have to copy it from another storyboard (they are just XMLs after all).
The simplest way would be creating a new project with Use Storyboard enabled, then right-click on your auto generated Main.storyboard, choose Open As ➔ Source Code. After that, copy the <!--Application--> part to your empty Storyboard.storyboard. Don't for get to grab the header and footer part of it, too. Below is just an example.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
</dependencies>
<scenes>
<!--Application-->
<!-- your copied content -->
</scenes>
</document>
Finally, right-click on your Storyboard.storyboard and choose Open As ➔ Interface Builder - Storyboard to resume the normal design view.

Related

Customizing AEM dialog - increasing all field's sizes

I have a carousel component for which there is a touch UI dialog naming '''cq:dialog''' .I need to increase size of all the fields of AEM dialog. Can anybody help me with this?
You can extend the aem style sheets by creating a clientLib:
Create a folder on file system. In this folder put a file with name content.xml.
The content of this must be
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
categories="[coralui3]" />
The most important thing is categories=[...]. The name of categoriy must be "coralui3".
During deployment your own css styles will be virtuelly added to your enviroment.
Then put two files into the folder. One file must be named with css.txt. The name for your other one can be named by your own. In example 'myown.css'. Open css.txtand put the name of your css file into it. See also this video on youtube.
If you want to apply your style on all dialog widgets, you style classes must be named like the classes from AEM itself.
In case you want to apply partially, you have create your own css class. Then open your dialogs xmls and add the keyword "granitCss=" to you prefered widget. See also here.

Shared TitleView in Xamarin.Forms AppShell

Is there a way to implement a shared TitleView component in Xamarin.Forms AppShell? I've tried a couple of approaches but it's not working as I intended.
What I'm trying to achieve is something like the following:
App Shell with a few tabs and a common Shell TitleView
The titleView is just a ContentView (let's call it Exposure) with a label to display the result of a calculation and a refresh button to fetch data and recalculate
Changing Tab shouldn't affect the state of the TitleView
What I've tried:
Initialize one instance of the Exposure component (View and ViewModel) and configure it on the DI framework to use that instance only (singleton).
When the Pages are initialized I get the single instance of the Exposure component and assign it to the Shell.TitleView property.
By doing this I was hoping that the Exposure state would be consistent across the tabs (single instance after all...), but what happens is that when I hit the refresh button it only refreshes the calculation on the current tab Exposure component, changing tab will present me with the Exposure component with old state. I'm surprised this is not supported out of the box (configure titleView at Shell level) but I might be missing something.
Might not be relevant but I'm using ReactiveUI (MVVM) and Splat (dependency injection)
The next thing I'm willing to try is to trigger a refresh when each page re-appears but that feels dodgy.
You can create a base ContentPage and set the style of TitleView of it .
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="xxx.BaseContentPage">
<NavigationPage.TitleView>
<StackLayout>
//...
</StackLayout>
</NavigationPage.TitleView>
<ContentPage.Content>
<StackLayout>
//...
</StackLayout>
</ContentPage.Content>
</ContentPage>

Save JavaFX scene into FXML file

Anyone knows how to save a JavaFX scene into FXML file that can be loaded by the JavaFX FXMLLoader?
The SceneBuilder allows to do it, but if I build the scene manually, how I can save it into FXML file?
If you mean build a fxml file from a running screen built in Java, the short answer is that you can't.
The fxmlLoader is designed to work only to load files, it references the class XMLInputFactory but not the XMLOutputFactory.
If you would like to do it by yourself, it is not only rewrite the classes read by the FXMLLoader, because there is a lot of reflection (java.lang.reflect) in that class.
So the long answer could be: you can do it by yourself using a lot of reflection and writing dynamic tags from class names, but there will be no guarantee that your fxml gives the expected results.
There is no such library, AFAIK, and I'm not sure if it's possible to create a generic one. It might be possible for simple cases, but even then it's a lot of work, I guess.
Here is the FXML format explained, if you want to give it a try: http://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html
You could traverse your scene graph/ node and generate an FXML file.
But why do you need the FXML format? It might be easier just to rewrite the layout in FXML instead of writing a library like this.
If you manage to write such a library - let us know! :-)
.fxml is just file extension,you can create it with any text file editor , i recommend you to use SceneBuilder either way, since you can create your UI and CTRL+C on root component , CTRL+V to notepad++ or other editor , and get source straight from there , edit to your liking.
To make it short, FXML is an XML based declaration format for JavaFX. JavaFX provides an FXML loader which will parse FXML files and from that construct a graph of Java object. It may sound complex when stated like that but it is actually quite simple. Here is an example of FXML file, which instantiate a StackPane and puts a Button inside it:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<StackPane prefHeight="150.0" prefWidth="200.0" xmlns:fx="http://javafx.com/fxml">
<children>
<Button mnemonicParsing="false" text="Button" />
</children>
</StackPane>
You want to specify controller as well with fx:controller=""
Or set controller in your code, whatever fits your needs.
if your question is more towards what pdem wrote , i suggest you to take a look at scenic View , you can get a lot of infomation from running application and recreate it based of it.If that aint sufficient , there is not much you can do.

JavaFX Scenebuilder does not see ids when FXML is in a different package than controller

i installed netbeans with java se7, and javafx samples are running fine. In scenebuilder, i can select an ID for each control defined and annotated with #FXML in my controller. however, i like my project organised. when i create a new package, and move my FXML file there, (myapp/views) and the controller stays in the root where it was -> myapp, then in scenebuilder does not seem to find the id.
I know about the 'controller class' in the FXML, but since i didn't move my controller, that should not be changed.
More specific, when both my controller and fxml are in the package 'holidayapp', it works. moving the fxml to a subpackage holidayapp/views', doesn't work. The controller class remains
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="holidayapp.HolidayViewController">
as the HolidayViewController remains in the root package. I do nothing else but moving the fxml file from the main package into a subpackage.
I would like to see the id's from the holidayViewController in my scenebuilder. Compoling and running with the fxml in a subpackage, was never any problem.
Thanks
I think you might be suffering from the following issue:
https://bugs.openjdk.java.net/browse/JDK-8091793
If you think you do, please consider to vote for and/or comment on this issue.
The way I worked with this was placing my Main class into the view (the one that extends Application). This gave me access to my Controller classes, their variables, and methods. This works for SceneBuilder 1.1.
I can only speak for when using Eclipse and not NetBeans so doing this may still result in nothing.

iOS project not showing Interface elements built from Interface Builder in my view

I am working on a project which includes many UI components on one view(being built in Interface Builder). I have found that after saving and moving my project directory, the interface which should include all of these elements, is empty(there are no visible UI components in the view).
There are actually 2 projects. 1 is a framework project, the other is the iphone project which i build & run on the device - everything is contained within a folder which i may move frequently as other members in my team work on it.
the view which is not properly showing elements, is an XIB file which can be modified through either the iphone project or framework project.
Why is this happening and how can i troubleshoot this problem further? I am not sure how to fix it.
Many components will not show if they're not been connected to a property, and some will not show if their datasource or delegate is not connected.
Have you wired everything up, making all of your connections?
Could you check the view hierarchy in the -(void)viewDidLoad ? As Matthew said, if those components are not connected to properties, they won't be shown. And, if they are not add onto proper view, then they won't be shown too.
You can check the view hierarchy of viewController by browsing the property subViews of self.view.