Am trying to connect the App Delegate to the View Controller in Xcode4, but I can't make the connection for some reason because App Delegate can't see it in the visual object editor.
Have added the view controller in the visual object editor, and changed the class ID to HelloWorldViewController, and have added the code in the App Delegate.h and .m files.
What am I doing wrong?
Here is the code:
testWindowBasedAppDelegate.h
// -- Add a forward reference to the HelloWorldViewController class --
#class HelloWorldViewController;
#import <UIKit/UIKit.h>
#interface testWindowBasedAppAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
//-- create an instance of the view controller --
HelloWorldViewController *viewController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
// -- expose the view controller as a property --
#property (nonatomic, retain) HelloWorldViewController *viewController;
#end
testWindowBasedAppDelegate.m
#import "testWindowBasedAppAppDelegate.h"
#import "HelloWorldViewController.h"
#implementation testWindowBasedAppAppDelegate
#synthesize window;
//-- synthesize the property--
#synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//-- add the new view to the current window --
[window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[viewController release];
[window release];
[super dealloc];
}
#end
You need to add an IBOutlet tag for IB to see it. Declare the property as,
#property (nonatomic, retain) IBOutlet HelloWorldViewController *viewController;
This even applies for methods that you want to expose but there you will use IBAction instead. For example,
- (IBAction)doSomething;
Both of these tags are just indicators and are actually declared as,
#define IBAction void
#define IBOutlet
Related
I am working on Xamarin Forms on VS 2017. Whenever I am running My IOS app it is asking for RootViewController but my other sample app is working perfectly without any exception.
My Other app has a default Implementation of Finishedlaunching. AppDelegate is inherited by FormsApplicationDelegate class
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
My main app works only after I have updated the Finishedlaunching Method. AppDelegate is inherited by UIApplicationDelegate class
UIWindow window;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Rg.Plugins.Popup.Popup.Init();
window = new UIWindow(UIScreen.MainScreen.Bounds);
window.RootViewController = new Login().CreateViewController();
window.MakeKeyAndVisible();
return true;
}
My question is when my other app is working fine with default code why my second application is not working and I have to add RootViewController.
Please let me know if I am missing anything.
I have a class SingletonBaseClass that is defined in C++ and later extended in QML. In the qmldir file, it is marked as a Singleton:
// qmldir file
singleton SingletonClass 1.0 SingletonClass.qml
// SingletonClass.qml
import QtQml 2.0
pragma Singleton
SingletonBaseClass {
// ...
}
This is the base class:
class SingletonBaseClass : public QObject
{
Q_OBJECT
public:
SingletonBaseClass(QObject* parent = nullptr) {}
// Get the owner engine
Q_INVOKABLE void someMethodCalledFromQml()
{
QQmlEngine* ownerEngine = ?
}
// Get the single instance of the given engine
static SingletonBaseClass* instance(QQmlEngine* engine)
{
SingletonBaseClass* instance = ?
return instance;
}
};
How can I retrieve the QQmlEngine instance in SingletonBaseClass?
How can I get a pointer to my singleton instance from within a static function?
Note: I have multiple QML engine instances in my application.
[Update]: I wasn't satisfied with the suggested workarounds and so I finally contributed this patch for 1. and QQmlEngine::singletonInstance() for 2. Both changes will be available in Qt 5.12.
If you want to get the QQmlEngine you can use the contextForObject() method as I show below:
Q_INVOKABLE void someMethodCalledFromQml()
{
QQmlEngine *ownerEngine = QQmlEngine::contextForObject(this)->engine();
qDebug()<<ownerEngine;
}
singletons in qml do not have a parent so a way to access them is by creating a property, for that we create a .qml and create an object with that property as the Singleton:
qrc:/tmp.qml
import QtQuick 2.0
QtObject {
property var obj: SingletonClass
}
and then this element is accessed by the following code:
static SingletonBaseClass* instance(QQmlEngine* engine)
{
QQmlComponent component(engine, QUrl("qrc:/tmp.qml"));
QObject *item = component.create();
SingletonBaseClass *instance = qvariant_cast<SingletonBaseClass *>(item->property("obj"));
return instance;
}
In the following link we show an example.
Why do I need so much (seemingly useless) pass through code that objc did not
require in a similar derivation:
class myNavigationController: UINavigationController {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
...
repeat ad nauseam for every single view controller of mine loaded from xib.
This should not be an issue if your don't want to overload the designated initializer init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) your UINavigationController subclass. If you just want to make use of the default (super) initializer, you can remove both those methods from your class.
I.e., the following class
// MyNavigationController.swift
import UIKit
class MyNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// I don't want to make use of this ...
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// ... nor this
}
// Things I do want to do with my nav. controller
}
can be reduced to
// MyNavigationController.swift
import UIKit
class MyNavigationController: UINavigationController {
// Things I do want to do with my nav. controller
}
Without any errors. (Verified in Swift 2.0, Xcode 7.2, simulator: iOS 9.2). This is expected behavior, see e.g. the accepted answer in thread 'required' initializer 'init(coder:)' must be provided by subclass of 'UITableViewCell'`.
If you still get an error when removing these for this subclass type, please give some details regarding your use of the class / Xcode version etc.
I have custom QWidget that contains custom QWindow. QWindow with OpenGL is used as a "connector" between render framework and Qt application.
Mouse and keyboard events are handled with overriding QWindow methods.
Pseudo-code:
class MyWindow : public QWindow
{
public:
MyWindow : QWindow() { /* GL stuff init*/ }
protected:
// mouse/keyboard event handling
// expose event handling
// resize event handling
// ...
};
class MyWidget : public QWidget
{
public:
MyWidget : QWidget()
{
auto window = new MyWindow();
auto container = createWindowContainer(window);
layout()->addWidget( container );
setAcceptDrops( true );
}
protected:
// overriding drop event, but is doesn't work
};
Question: how to handle drop events (it doesn't matter where)?
Problems:
QWindow doesn't provide virtual methods for drag-n-drop support.
QWidget::dragEnterEvent, QWidget::dropEvent (and similar) are not called.
QWindow still accept mouse events, even setMouseGrabEnabled( false ); is set.
Note: I found that call of setMouseGrabEnabled( false ); doesn't blocks mouse events handling in QWindow.
I found a solution:
It is necessary to install event filter on QWindow and process events there (eventFilter).
It is possible to install event filter on QWidget (container) but it doesn't work on OS X. Probably it is a bug in Qt, because under Win everything is fine.
I need to open a view as topViewController from the AppDelegate method :
(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:
(NSString *)sourceApplication annotation:(id)annotation
but I don't know how to make the reference to the slidingViewController....