I have a Spritebuilder project that i want to use with Soomla In App Purchase framework. In Spritebuilder, i have a button with "store" as selector for cccontrol. In Soomla documentation, the code that opens storefront is this:
[[StorefrontController getInstance] openStoreWithParentViewController:self]; // 'self' is the calling UIViewController
Normally in Xcode, i will do this:
- (void)store {
CCScene *storeAssets = [CCBReader loadAsScene:#"StoreAssets"];
[[CCDirector sharedDirector]replaceScene:storeAssets];
}
For this case, how do i integrate the Soomla code into Spritebuilder since it don't use UIViewController?
- (void)store {
//Soomla code
}
Related
I want to flash the scrollbars of a ListView in Axway / Appcelerator Titanium. So I cast a Titanium ListView to a iOS UIScrollView and then try to call the flashScrollIndicators method on it, but I get an exception. Does anyone now how to accomplish this? See my code below:
-- View
<Alloy>
<Window onOpen="onWindowOpen">
<ListView id="listView">
etc...
-- Controller
// After displaying the ListView I call:
var UIScrollView = require('UIKit/UIScrollView');
var listView = UIScrollView.cast($.listView);
listView.flashScrollIndicators();
The $.listView object is natively a subclass of UIView, not a UIScrollView. It contains a UITableView as a child view. You could access the tableview like this:
var UIView = require('UIKit/UIView');
var listView = UIView.cast($.listView);//you cast it to be able to access it's native properties
listView.tableView.flashScrollIndicators();
Haven't tested it but I guess it should work.
When in doubt about the type of a Titanium UI element, just go and check the source code by opening the project compiled in the build/iphone directory. Open it with XCode and search for the header file.
I'm creating an application and I want the status bar hidden. When I test the app, the status bar is hidden whilst the splash screen is shown, but once the app is fully loaded, the status bar reappears.
I'm using Xcode 5 and iOS 7, and have tried disabling the status bar programatically
([[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];),
in the info.plist file, and using the attributes inspector on the .xib file. Nothing appears to work.
Any ideas?
Try adding the following method to your app's root view controller:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
You should add this value to plist: "View controller-based status bar appearance" and set it to "NO".
This will enable you to set the status bar to hidden mode. This sets it to a global unlike other provided answers.
UPDATE: If you want that the status bar would be hidden on splash screen don't forget to mark "Hide during application launch" on target status bar options.
Also, you can add "Status bar is initially hidden" to "YES" on the plist if you don't want to do it with code inside the app.
The code you posted works for iOS 6.1 and below. For iOS 7, Apple has made new methods available to directly control the status bar for each view. Turning off this option in your Info.plist will enable you to hide the status bar, at least for the current Developer Preview (4).
For reference, please take a look at the iOS 7 transition guide that's available on Apple's developer portal.
well I try hide the status bar in all my app and in the "app"-info.plist and I add two rows in the dictionary "Information Property List" I add "View controller-based status bar appearance" set NO and in "Status bar is initially hidden"set YES and for me works n_n'
However, if you use UIImagePicker, the status bar appears again.
In that case, you should hide the status bar as below,
- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// for iOS7
if ([self respondsToSelector:#selector(setNeedsStatusBarAppearanceUpdate)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
After some long searching, I finally found a very simple solution which also takes care of the UIImagePickerController problem.
As mentioned in the other answers, set your status bar hidden in your AppDelegate didFinishLaunching, and set the "View controller-based status bar appearance" to NO.
Then, in your AppDelegate:
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
et voila - your Status Bar will remain hidden even when the UIImagePickerController is foremost.
This is better than 'rehiding' it every time you present a UIImagePickerController as it remains hidden throughout the app.
To hide the status bar on a particular UIViewController, simply add this:
-(BOOL)prefersStatusBarHidden
{
return YES;
}
Hope this helps !
You can hide from the project summary. there is a checkbox hide during launch.
See the snapshot
I found this solution for me. It works like a charm.
Write this code on your viewcontroller which you wanted to use UIImagePickerController on.
- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
- (void)viewWillAppear:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
In addition to the answer from alones above, make sure to implement the imagePickerControllerDidCancel method and add the same code there too.
I was having issues with UIImagePicker as well. Similar to Alones answer, my solution was the following. I added this line or code:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
to this function:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
I haven't tested this with iOS 6 or older but it works great in iOS 7.
Swift Solution
just add this to your view controllers:
override func prefersStatusBarHidden() -> Bool {
return true
}
I am using Xcode 6, this solution works on iOS 7 and 8 for me:
First, Set the "View controller-based status bar appearance" to NO in plist file.
Second, in AppDelegate, add this:
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame
{
[application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
My problem was that I used view controller containment. Only the top most view controller, which is embedded into a navigation controller for example, can hide or show the status bar.
I am building an iOS app in Rubymotion. I want to create a custom tabBar so I need
to use a real tabBar but hide it. How can I hide the tabBar in Rubymotion?
To hide the tab bar you can use hidesBottomBarWhenPushed.
The Objective C is:
MyController *myController = [[MyController alloc]init];
myController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myController animated:YES];
[myController release];
Therefore the RubyMotion Code is
#my_controller = MyController.alloc.init
#my_controller.hidesBottomBarWhenPushed = true
self.navigationController.pushViewController(#my_controller, animated:true)
I hope this helps. If you'd like to see more references to tab bars please check:
https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_2/12_tabbars
Or if you'd like to see basics of navigation controller please check
https://github.com/IconoclastLabs/rubymotion_cookbook/tree/master/ch_2/11_navbarbuttons
I hope this helps!
I have made a button so that when it's pressed by the user and a particular row(s) are selected it does something.
So far I have this:
if (pickerView selectedRowInComponent:0) {
[mailComposerTwo setToRecipients:[NSArray arrayWithObjects:#"email#blah.com",nil]];
}
It works on its own. But when I do the if statement multiple times it crashes.
An ways of making it work?
Any help appreciated, thanx.
The problem probably lies with your mail composer, not the picker view. When you show the composer, make sure that you only create it if it hasn't already created.
Also, make sure you release it after you show it:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
...[configure the picker]
[rootContainer presentModalViewController:picker animated:YES];
[picker release];
NSArray *finalList = [[NSArray alloc]init];
//put all your if statements
if (pickerView selectedRowInComponent:0)
{
[finalList arrayByAddingObjectsFromArray:#[#"email#address.com",#"second#address.com",...];
}
if (pickerView selectedRowInComponent:1)
{
[finalList arrayByAddingObjectsFromArray:#[#"another#address.com",#"fourth#address.com",...];
}
//end of if statements
[mailComposerTwo setToRecipients:finalList];
[self presentViewController:yourInitializedMessageController animated:YES completion:^{NSLog(#"message controller is presented");}];
This will do a single method call rather than continually reassigning which for some odd reason is causing your exception. presentModalViewController:animated: has been deprecated as of iOS 6.0? if not 7.0 I believe.
NOTE! Make the message controller a property of the main view controller. It is good practice so that it is not auto-released by iOS if you need to bring it back up. However if you use MFMessageComposer iOS will keep messenger allocated or running in a thread somewhere so initializing a view controller for it is quick.
I am developing a C++ app and I need to display a NSWindow with a WebKit WebView inside it. I've coded up the Objective-C class which will manage creating and displaying the window but the WebView contained inside it does not display. Here is my code. Any idea on what is wrong and how I can fix it?
I'm compiling the below code with
$g++ -x objective-c++ -framework Cocoa -framework WebKit Foo.m main.m -o test
Foo.h
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#interface Foo :NSObject {
NSWindow *window;
WebView *view;
}
- (void)displayWindow;
#end
Foo.m
#import "Foo.h"
#implementation Foo
- (id)init {
self = [super init];
// Window Container
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(500.0f,500.0f,250.0f,250.0f)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreNonretained
defer:NO];
// WebView
view = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 250.0f, 250.0f)
frameName:#"Frame"
groupName:nil];
[[view mainFrame] loadHTMLString:#"<html><head></head><body><h1>Hello</h1></body></html>"
baseURL:nil];
return self;
}
- (void)displayWindow {
NSLog(#"In Display window");
[window setContentView:view];
[window setLevel:NSStatusWindowLevel];
[window orderFrontRegardless];
sleep(5); // leave it up for 5 seconds
}
- (void)dealloc {
[window release];
[super dealloc];
}
#end
main.m
#import "Foo.h"
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
Foo *foo = [[Foo alloc] init];
[foo displayWindow];
[foo release];
[pool release];
return 0;
}
You need to run the run loop. If you just order the window in and then exit, that's exactly what will happen: The window will appear, and then (five seconds later) your program will exit. You can run the run loop by telling the application (which you create but don't otherwise use) to run.
On the main thread of a Cocoa app, sleep is always the wrong answer. The same goes for its Cocoa cousins, +[NSThread sleepUntilDate:] and +[NSThread sleepForTimeInterval:]. The run loop will let you tell it to run for a fixed amount of time, but that won't get the application running; you do need to send the application the run message, which provides no opportunity to exit after a fixed interval.
The solution there is to first create an NSTimer object whose target is the application and whose selector is #selector(terminate:). Create it scheduled and non-repeating, with the interval set to five seconds. (Creating it scheduled means you don't need to schedule it separately—it is already ready to go from the moment you create it.) Then, send the application the run message. Five seconds later, the run loop will fire the timer, which will tell the application to terminate itself. This is assuming that you actually have a good reason to make your application quit after five seconds.
As noted by Yuji, every window in modern Cocoa should use NSBackingStoreBuffered.
And don't forget to release what you have created; you currently are forgetting that in the case of the view. See the Memory Management Programming Guide for Cocoa.
Once you have this working, I suggest moving toward a more typical architecture for this application:
Create a subclass of NSObject, and make an instance of that class your application's delegate.
Put the window and its WebView into a nib, and have the app delegate create a window controller to load and own the contents of that nib.
The app delegate should also be responsible for loading the page into the WebView and for setting up the self-termination timer.
Finally, create a nib to hold your application's main menu (the contents of the menu bar) and the application delegate. Interface Builder has a template for the first part; you create the app delegate object by dragging a blank Object in from the Library, setting its class on the ⌘6 Inspector, and dragging the connection from the application to the object. Then, you can reduce main to the single line that Xcode's project templates put in it: return NSApplicationMain(argc, argv);.
Doing all this will help your understanding of Cocoa, as well as your maintenance of the application—cramming everything into main will not scale.
You should also read the Cocoa Fundamentals Guide, if you haven't already.
Don't make it sleep. It stops the execution of the main thread, in which the GUI is dealt with. Instead, you need to run the run loop. Also, Cocoa needs to set itself up. So, call [[NSApplication sharedApplication] run] to set it up correctly and run the event loop.
Also, don't use backing mode other than buffered mode. Other modes are remnants from the time immemorial, and only NSBackingStoreBuffered should be used. As discussed in this Apple document, the non-retained mode is a remnant to support Classic Blue Box (OS 9 virtualizer), and newer classes like WebKit just can't operate within it.
So, what you need to do is practically:
change NSBackingStoreNonretained to NSBackingStoreBuffered.
Remove the line
sleep(5);
add a line
[[NSApplication sharedApplication] run];
after
[foo displayWindow];
Also, in order for an app to receive events from the window server correctly, you need to pack it into an app bundle. Compile it into a binary called foo, and create the following structure:
foo.app/
foo.app/Contents/
foo.app/Contents/MacOS/
foo.app/Contents/MacOS/foo <--- this is the executable
Then you can double-click foo.app from the Finder, or just call ./foo from the command line.