I am a learner in the area of Objective-C. I'm trying to build an iPhone app with cocos2d. Now I would like to use a UITableView to show data from an XML file.
Is it possible to use UITableView with cocos2d and is it also possible to retrive data from an XML file?
You can very easily integrate UIViews with cocos2d scene by using CCUIViewWrapper class which was made by someone and posted on cocos2d forum. I had used it and it is pretty simple to use everything is there on the forum.
And for XML parsing it's better if you use the parser provided by iOS as Jonathan said cocos2d is a game engine which doesn't provide any mechanism to parse XML files.
Absolutely! The XML file doesn't even have to be local in your app.
I recommend parsing the XML with something like TouchXML. The only built in iPhone XML parsing library is a event based one that is hard to use unless you have the right sort of structure in you data.
Then in the table view methods that fill your table with data, select items from the variables that you have parsed out of the data file.
Yes, Squeegy is right. I do want to correct a conceptual misunderstanding you appear to have, though. Any iPhone application you write will always be based on the core iPhone APIs. Thus, your using Cocos2d is irrelevant to your use of UITableView. As for XML parsing, that is, of course, not done by Cocos2d. Cocos2d is a high-level abstraction of OpenGL for relatively easy game development; XML parsing is not in its purview. Thus, again, your use of Cocos2d is irrelevant to your use of an XML parsing library.
It is possible to use UITableView objects, UINavigationViewControllers etc alongside your Cocos2D app.
Just create a UIViewController in applicationDidFinishLaunching and add it's view to the window.
Hold onto the EAGLView* Cocos2D uses, and switch between this OpenGL view and your view controller (with it's table views, buttons, and what have you).
If you want to display a table simultaneously with your Cocos2d content, it might be best to use the UI elements they provide.
There is also the possibility of using cocos2d extensions. These are pretty much some UIKit classes rewritten in cocos2d.
Here is a link I found with scroll and table views.
There isn't much explanation on how to use it, but it doesn't differ too much from UIScrollView and UITableView.
Related
I'm trying to get to grips with using Chipmunk (not the Obj-C version) with UIKit components on iOS, and still struggling immensely.
I'm trying to establish how, in the ChipmunkColorMatch example in the documentation, the UIButton instances are actually hooked up to any of the physics calculations. I see that the UIButtons are created inside the Ball class, and some of their properties are set, (type, image, etc.), but I'm not understanding where the cpBody or cpShape or whichever it is is actually attached to that UIButton. I assume it needs to be, else none of the physics will be reflected in the UI.
I've looked in the SimpleObjectiveChipmunk tutorial on the website too, but due to the fact that it uses libraries unavailable to me (the Obj-C libraries), I can't establish how it works there, either. Again, I see a UIButton being created and positioned on-screen, but I don't see how the cpBody (or in that case, ChipmunkBody) is linked to the button in any way.
Could anyone shed some light on how this works? Effectively what I'm going to need are some UIButton instances which can be flicked around, but I've not even got as far as working out how to create forces yet, since I can't get the bodies hooked up to the buttons.
Much obliged, thanks in advance.
EDIT: Should also point out that I am not, and do not want to use cocos2d in this project at all. I've seen tutorials using that, but that's a third layer of confusion to add in. Thanks!
Assuming this source is the project you're asking about, it looks like the magic happens in Ball's sync method -- it creates a CGAffineTransform representing the translation and rotation determined by the physics engine, and applies that to the button.
In turn, that method is called by the view controller's draw: method, which is timed to occur on every frame using CADisplayLink, and updates the physics engine before telling each Ball to sync.
I am reading Apple documentation regarding AVFoundation framework. I want a NSView in my Cocoa application to play video in my application. It's a tutorial video something similar to what apple provides in their application.
My question is, while reading this document...
AVFoundation programming guide
Most of the classes mentioned are related to iOS as an example...PlayerView extends from UIView.
Now, before I code I want to ask should if I am making application using same example code for Cocoa App should I read UIView as NSView? is that the solution?
I haven't tried as it's lots of code, I thought it's better to understand it before start coding.
In this specific example you should be ok replacing UIView with NSView with possibly some minor changes, since it seems like a lot of the work is being done on the view's layer, which is a property that exists in AppKit as well as UIKit for NSView and UIIView respectively.
I am not sure what you overall goal is here, but as long as you are not intending to copy the doc line for line, you'll be ok; ie you might need to make small changes.
Hope this helps.
It sounds like you want a simple QTMovieView loaded up with a video to play
I'm a relatively new iOS developer, with most of my previous experience coming from .NET.
My application is a canvas like system in that there is a parent UIView that contains all the objects the user is placing/resizing/etc as subviews. I want to be able to save these positions/configurations to named files.
In .NET, I would have simply subclassed UIView, given it a "title" property, then serialized this to file, and then deserialized them to load them back, but in Cocoa I'm quite lost.
Originally I thought I could do this using NSCoding, but this doesn't seem to be a good solution for multiple file saving.
So I looked at Core Data, but I'm not sure how I can create Core Data objects of existing Cocoa UIKit classes like UIView.
I've spent a while googling and can't find any information about this kind of predicament.
What should I use, and what is the best way to go about it?
You probably could do it with NSKeyedArchiver, since UIView implements NSCoding. A more MVC-oriented design, however, would be to have the user manipulate a data model by moving the views around. To save, you'd archive the model rather than the views themselves.
Is there disadvantages to using WebKit WebViews compared to using NSViews?
I'm using a webview to create a UI for an application. The application itself does not have much interactivity. I have seen it mentioned, on this website & others, that using a WebView can be convient means of prototyping.
However, with our team this seems like an ideal way to produce the production ready UIs, especially with WebKit. Are we missing something?
Thanks,
Ross
Okay, so you seem to be asking if using an HTML interface (presented via a WebView) for your application has any disadvantages.
The answer to this is "no", at least "not necessarily". This is analogous to building an iPhone specific web application, and there are some excellent examples of those. The caveat would be that a lot of those sites end up recreating the look and feel of a native iPhone app, for consistency and to make the users feel "at home".
Given that you're developing a native app anyway, it seems a shame to throw away, or recreate, the responsiveness and appearance of the native chrome. Of course, for certain types of applications (games are an obvious example) a user has no expectations about the application's UI, so you're free to knock yourself out.
The other factor to consider is the amount of interactivity (although I notice that you say there isn't much in your case). The native controls will make coding a lot simpler than having to capture all user input through the "filter" of a WebView, even though using one might make the initial layout of the screens easier.
I hope that's the sort of answer you were looking for (although it's mostly non technical).
As you might have known if you spend some time in the documentation, you'd have seem that WebView is a subclass of NSView.
The documentation says about WebView:
WebView is the core view class in the WebKit framework that manages interactions between the WebFrame and WebFrameView classes. To embed web content in your application, you just create a WebView object, attach it to a window, and send a loadRequest: message to its main frame.
And about NSView:
NSView is a class that defines the basic drawing, event-handling, and printing architecture of an application. You typically don’t interact with the NSView API directly; rather, your custom view classes inherit from NSView and override many of its methods, which are invoked automatically by the Application Kit. If you’re not creating a custom view class, there are few methods you need to use.
So here's the answer to your question:
Is there disadvantages to using WebKit WebViews compared to using NSViews?
Yes. You can't display any web content with NSView. That's what you need WebView for.
I suggest reading some more documentation though.
I have a large number of UIViews that are created in the app delegate applicationDidFinishLaunching and added to an NSMutableArray. The user pages through these views using a page control and scroll view. I created the UIView and its child components in IB. They are wired to a controller. To create 170 views on the iPhone takes about 30 seconds. Eventually, I'll have over 1000 views. Besides being slow, it will also kill the app because of memory use. How much faster and memory efficient is creating everything programmatically without views? How might some of the 6000 fact type apps be doing it?
Is there a better approach instead of creating everything at once? The user may access a view in slot # 400 and begin scrolling from there. Any suggestions are appreciated.
UIViewControllers are lazy. They only load when requested, and automatically unload when memory is tight (and it's easy to unload them manually by calling self.view=nil).
"Load" here means "read a NIB," or "build programmatically." ViewControllers don't really care. Building programmatically can be a little faster since you don't have to hit the disk, but this is seldom the bottleneck, since you only display one view controller at a time.
As to which way to go, it's more style than performance (with the exception of UITableViewCells, which there are reasons you need to build programatically in most cases).
Start by studying the View Controller Programming Guide. It'll show you how iPhone intends you to do this.
To eJames' comment about NIBs being XML files, this may be slightly misleading. NIBs are binary files generated by compiling XIB files which are XML. I'd do actually profiling on the phone before assuming that NIB load time is actually a problem. Much as I am by nature inclined to programatic layout, I've found in practice that NIBs greatly simplify many UI issues in practice, and I always come back to them for large projects.
It is difficult to suggest an answer without knowing a little bit more about your specific problem, but I would venture to say that if you expect to display 1000 different things, creating 1000 individual views in IB is not the way to go.
If your pages share a common layout, you can use a UITableView to display the content of each page, and store only the data for each page in your NSMutableArray.
An excellent tutorial on how to use UITableView can be found here.
If they do not share a common layout, laying things out programmatically will be the way to go. This should be no more memory or processor intensive than doing it using IB, and in fact it will probably be faster, since it removes the need to read and parse an XML file (which is what .NIB files actually are).