Possible to use iPhoneSimulators framework in a Cocoa App? - iphone

I am toying with the idea of creating a iPhone UI editor that isn't Interface Builder! Mostly to see if it is possible to do... I have been able to link to the UIKit.framework in a Cocoa app that I have created by dynamically loading it (via NSBundle functionality). I have been able to instantiate an UIView from there. Now the question is... how do I get to whatever the UIView renders?
I am trying to figure out how Apple implemented their Simulator since it seems likely that they are using the frameworks under the iPhoneSimulator.platform folder to do the rendering and then displaying that in a Cocoa window...
I am not sure how far I can go with this idea..but if anyone has any ideas how to direct the output of the UIVIew to a bitmap then I could take that and display in my Cocoa window...
Thanks,
Peter

You might try making an NSView subclass that hosts a UIWindow. In the NSView's drawRect:, apply any necessary transformations, then send drawRect: to the UIWindow.
Then, set your simulator NSWindow's content view to an instance of that subclass.

Related

Return to mainview from webView deployed using storyboard

I created a new project "Single View Application" and designed the mainView with Storyboard. My main view contains a UIButton that opens the camera, the camera scans barcode and automatically goes to a website. Now I created a webView programmatically so that website can open and also created a UIButton inside the webView. Now I want that UIButton to act as home botton and return to mainview. I am unable to do that, please help.
ViewController.m code: http://cl.ly/FKj8
My storyboard looks like:
You really should look into the View Controller Programming Guide -- by switching around the contents of a single view controller, you're making a lot of extra work for yourself with little benefit. By using multiple view controllers when you want to have different "screens" in your app, you can take advantage of storyboarding for easier development, and you automatically get better memory management (read: less potential for crashes), too.
However, to more directly answer your question... if you're putting the WebView into the view hierarchy with [self.view addSubview:webView], you can remove it with [webView removeFromSuperview]. (This means you'll have to keep a reference to the WebView around so you can refer to it when you want to dismiss it.)
I also noticed in the code you posted to cl.ly an unrelated method -deviceModel which uses uname() to get device information. This is a bad idea, for two reasons:
uname() isn't guaranteed to do something useful on an iOS device (even if it currently does). Use the UIDevice class instead if you need this kind of info, or...
Generally, you don't want to test for the device name to enable functionality in your app; instead, you should test for the capabilities you need. (For example, if you look for a device name starting with "iPhone 4" to test for a Retina display, you'll miss the 4th-generation iPod touch, and the iPhone-5-or-whatever-they-call-what's-next. Instead, use the UIScreen class.)

How to generate .m/.h files from Storyboard?

Is there a convenient way to generate code from any new view controllers I've created on the storyboard? For example when you create a new iOS application, XCode will set up a skeleton class for your view controller.
Thanks!
I don't think so. You need to create a new ViewController subclass in XCode but uncheck the "Create Xib for this class" box (not sure if that is exactly what it says). Then select your newly made view controller in storyboard and change it to the class you just created.
Ok the skeleton you are talking about is just a template for your application. You are asking for a dynamic template generator from your storyboard and maybe Apple can figure out how to do this in a non distant future but in this moment I think you can't do that. After you created the storyboard file with your complex scheme you need to manually create all your viewController subclass you used in the storyboard. It's not a big deal ... I suppose your application doesn't have thousand ViewController so you can do it manually.
Apple are working hard to simplify developers job but Xcode can't do everything for you.
You can try to post this answer directly to Apple throughout the bugreport Apple website and post it as improvement to implement in future Xcode release.
Lets try it :)

iPhone Cocos2D - where to load the code?

I am starting to learning Cocos2D for iPhone. I see the basic template has a viewController but when it runs it loads HelloWorldLayer, instead of the viewController view.
When you work with a viewController, you used to have the main logic for that controller on the .m, but as Cocos2D works in another way I wonder where should I put the main logic code.
What I mean is this. Developing with Cocos2D I will have a bunch of these "layer" files and as I pass the scenes, one of these files will be active at one time but now imagine that I am building an app that has in-app purchases or coredata. I have to have one central place where this common logic to handle sales and the database should reside. Where is the best practice? To put it on the viewController Cocos2D creates or what? How do you do that?
Where do I put the code so it will initialize when the app runs and before showing the first scene?
thanks
The startup code in Cocos2D is in the app delegate applicationDidFinishLaunching method. So you may want to initialize your loading code there.
The issue you're experiencing may be due to the incorrect setup of the view controller by Cocos2D, which leads to the view controller's viewDidLoad method not to be called. You can call that manually from applicationDidFinishLaunching however, after the line: rootViewController.view = glView
You'll find plenty of Tutorials that shed more light on this here: http://www.raywenderlich.com/

iPhone: how to load objects *after* the main viewcontroller has appeared

Ok hopefully this is an easy question:
I have a main viewcontroller that is loaded by the app delegate at application startup.
This viewcontroller has some code in 'viewDidLoad' to create some non view type based objects (some sound/data objects). Aside from that it also loads a UIView.
The sound/data objects take a while to create, but the app is quite functional without them for a start - so I want to load these objects after the UIView has loaded, but can't seem to figure out how.
I have tried moving the appropriate code to viewDidAppear, but this is still called before the UIView actually appears on screen. Is there a function that is called after the viewcontroller actually starts displaying UIViews, or any other way to achieve what I want?
Any help would be much appreciated - thanks!
In case anyone else has a similar problem, I found a way to solve it: use NSThread to load things in the background without pausing everything else.
There's a good simple example here: http://www.iphoneexamples.com/.

UIPopOverController for iPhone (currently only available for iPad)

Before I implement something similar for the iPhone, I'm wondering if anyone has implemented something similar of the UIPopOverController for the iPhone. This is so far only available for iPad.
See my implementation here: https://github.com/werner77/WEPopover
It has the same interface as the UIPopoverController but is generalized for iPhone and with support for custom background views.
I have provided another alternative SGPopoverController at http://github.com/KJoyner/SeaGlass. Like the WEPopover, this has a similar interface to UIPovoerController but works on the iPhone. This version handles more corner cases, works both modally and non-modally, supports passthrough views, and more.
Create
UIPopover+iPhone.h
#import <Foundation/Foundation.h>
#interface UIPopoverController (overrides)
+ (BOOL)_popoversDisabled;
#end
There's a reason UIPopoverController isn't a standard UI element on the iPhone, is that screen space is rather restricted. Having a popover, that's easily readable, implies that a fair amount of the iPhone screen will be taken up by the popover. Perhaps you should rethink your UI decision.
Maybe a coverVertical modal view?
Found another git. Looks more updated and actively maintained. it uses QuantzCore to draw the popover, which looks as elegant as iOS's SDK native.
Just for your reference: https://github.com/50pixels/FPPopover
Basically the best way to do this is to implement custom UIAlertView subclasses that look/behave how you want, via custom animations and being able to click behind and disappear (if you want that functionality, as UIPopoverController has it)
Edit: you can also try using a view and presenting it modally, though the animations might not be what you are looking for.