I want to implement an application for iOS. I’ve used Qt 5.3 on Mac. I want to defined user interface in Qt. I want to have a button on *.ui. When clicking on that, iOS photo library will be opened and then user can be able to select a photo. I know that I must use UIImagePickerController.
I have to use the root controller and show the UIPickerImageController on that.
For doing so, I need to use some internal Qt API:
first, in the *.pro:
QT += gui-private
then, in my *.mm code get the pointer to the root view controller of the Qt app:
UIView *view = static_cast<UIView *>( QGuiApplication::platformNativeInterface()->nativeResourceForWindow("uiview",quickView) );
UIViewController* rootCtrl = [[view window] rootViewController];
and now, I can show the UIImagePickeController:
[rootCtrl presentViewController:imagePickerController animated:YES completation:nil]
this way to get the root view controller with QML, solved my problem but I don’t want to use QML. Is there another way to get a pointer to the main root view controller of the Qt application(C++ + Objective-C) without using QML?
Thanks!
You can use UIApplication and keyWindow property:
UIViewController* rootViewController = [[UIApplication sharedApplication].keyWindow rootViewController];
Related
I have been working on a fullscreen loading view for my apps, but it can't block any user interaction. The way I implement it is like this:
Create a singleton object - LoadingView
Call [LoadingView show] - add the loading view to [[[UIApplication sharedApplication] delegate] window]
So I want to ask :
Is my concept wrong?
Are there any method calls that can disable all user interaction to my apps?
Is there another better way to do this? (I prefer knowing about the principle inside than just using others' libraries)
Thanks
I use such way to block user interaction:
create UIView with window frame
set view's user interaction enabled to true
(optional) add UIActivityIndicator to view
add view to window subviews
when I need to show it I set hidden to NO and use bringSubviewToFront function to show loading view
when I don't need it I set hidden to YES and use sendSubviewToBack
id application = [[UIApplication sharedApplication] delegate];
UIView *loadingView = [[UIView alloc] initWithFrame:[[application window] frame]];
loadingView.userInteractionEnabled = YES;
loadingView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[[application window] addSubview:loadingView];
Are you wanting to create a splash screen when the application starts? If so, all you need to do is add an image file called Default.png and/or Default#2x.png (for retina displays) to your project. This image will work as a splash screen for when the app launches.
You can also control the splash screen info.plist file.
Read more about the iOS launch screen here.
I've made a diary application for iPhone and I want to make it universal (iPhone and iPad).
When the application Launches in iPad, I want it to use a split view controller.
I have two classes. The first one is "Rootviewcontroller" and the second one is "Detailview" Controller. In both classes, I use the navigation controller. In the iPhone, when the application launches, rootviewcontroller is visible. Using the navigation controller, the user can move to the detail View.
On the iPad, I want the root view controller to be on the left side of the split view controller, and the detail view on the right side.
If you check out the Apple Documentation, you just have to assign the two view controller when you initialize the UISplitViewController. Here's a link to the Apple Documentation - http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewController_class/Reference/Reference.html
Here's an example from an actual iOS application we have (changed some variable names to make it easy to understand). We basically determine if the device is an iPad or not, then build the master navigation controller.
detailNav is the a navigation controller created with the "detail view controller of our item"
masterNav is the navigation controller used with our iPhones. It starts the users on a tableView which allows them to select an item to move forward to a detail view.
We assign both of these to an array and initialize the split view controller.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detailVC];
NSArray *vcs = [NSArray arrayWithObjects:masterNav, detailNav, nil];
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
[splitViewController detailVC];
[splitViewController setViewControllers:vcs];
[[self window] setRootViewController:splitViewController];
} else {
[[self window] setRootViewController:masterNav];
}
This is most likely not the best code or best practice as me and my team are still fairly new to the iOS world, but I hope it helps. This code is running on a live app in production.
Here's apples docs on how to do it: http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html
To implement the split view it is in the iPad view controller, if you want to change the side the split view is on you can subclass it and redraw it on the right. Hope this helps!
In an alert view method I implemented the following (pretty standard) piece of code for popping a modal view:
else if (buttonIndex == 1) {
EmergencyPlanViewController *emergencyPlanView = [[[EmergencyPlanViewController alloc] init] autorelease];
[emergencyPlanView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:emergencyPlanView animated:YES];
}
Somehow it gives me a black screen as result. I can't find what is wrong here.
I created the window in my MainStoryBoard and customized the class of the viewcontroller in IB to EmergencyPlanViewController.
The viewDidLoad method of the emergencyPlanView is triggered but it looks like the view is not loaded. Anyone an idea what's wrong here?
EDIT:
To be clear, I am not using seperate xib-files in my project. I only use the storyboard
In the xib file, is your UIView set to the File Owner's view. That is probably the problem. Also if you just apply init, that will load the EmergencyPlanViewControllerinterface builder file with the same name:
EmergencyPlanViewController.xib
So make sure in that case that either:
The EmergencyPlanViewController nib is indeed: EmergencyPlanViewController.xib
or that you write instead of init: initWithNibName://whatever nib name here
I managed to fix the black screen issue when presenting a modal view controller by setting a background color to the view in Interface Builder. I noticed that by default the background color of the view is set to something like black/white (see picture attached), although it appears in white. I don't know exactly what does this mean or how it is responsible for showing a black screen, but setting a single color or texture fixed it. PS: I've faced this when migrating from iOS SDK 5 to 6.
ios6
Try this:-
EmergencyPlanViewController *emergencyPlanView=[[EmergencyPlanViewController alloc] initWithNibName:#"EmergencyPlanViewController" bundle:nil];
emergencyPlanView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:emergencyPlanView animated:YES];
i am unable to get the pushViewController to work on a View Based Application on the iPhone. On my 'ProjectViewController' i have a IBAction with the following code :
-(IBAction)switchAugmented
{
ARViewController *viewController = [[ARViewController alloc] initWithDelegate:self];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
When i run the program and press ibaction nothing happens. Besides that statement above do i need to do anything else to make the view appear? what am i missing?
(...) on a View Based Application (...)
You just have no UINavController! Try to embed your main view in UINavigationController and everything will start working.
Double check to make sure that the button you are pressing is connected to the right method in interface builder. Also try putting an NSLog statement in the switchAugmented to see if the method is getting called.
You also have to check and see if you have a UINavigationController instance, otherwise you won't be able to push a new view controller.
You won't be able to push a new view controller in a View Based Project. You need to create a Navigation Based Project or add an instance of the UINavigationController in your Main.nib (if your using a nib file) only then will the push view controller will work
I am trying to create a reusable "picker". It is basically like a keypad of a phone. Since I will be using this a lot in my iPhone app, I have been frustrated with trying to make it appear.
It is in its own XIB file and has its own UIViewController subclass as the FileOwner.
However, when I instantiate this with:
MonthPickerViewController *mpvc
= [[MonthPickerViewController alloc] initWithNibName:#"MonthPicker"
bundle:nil];
Nothing happens on the screen. Yet is does fire the -viewWillAppear methods, etc.
So, what am I doing wrong either in code or in InterfaceBuilder that is preventing my view to appear?
Are you pushing the view controller?
[[self navigationController] pushViewController:mpvc animated:YES];
Or are you adding the view controller's view as a subView of your current view?
First, make sure you've hooked everything up right inside Interface Builder. An easy gotcha is to forget to connect the View object up to the view outlet of your UIViewController subclass.
Then, as Adam says, you need to actually display the view. Assuming you're doing this inside the code of another view controller, you'd need something like the following if you just wanted the new view to appear ontop of your current view:
[self.view addSubview:mpvc.view];
Of if you are using a navigation controller to stack views:-
[[self navigationController] pushViewController:mpvc animated:YES];