Define Layout, GUI by Code at Runtime - iphone

Net Developer planning a new Product.
It will amongs other things generate dynamically its User Interface from a downloaded File.
I read that file and depending on it i create the necesseray buttons, labels, tables etc..
I wish to outsource that similar kind of product for a development for the IPhone..
So my question to Iphone experts is. Is this possible with the Iphone too?
With 'possible' I mean basically if it is technically possible and if it is 'allowed' on MacStore..
Any feedback is much appreciated...

The user interface files on the iOS, the (the XIB files), are nothing more than a files containing archived objects. So when you create a static interface in Interface Builder, what Xcode actually does is to create objects for all the UI elements, setting the object properties according to your wishes, setting up the object graph (which objects has references to which other object) and finally archives the whole graph into a file. When you load a XIB file, the objects are simply unarchived and you get an object graph with all the UI objects in their desired states.
That means whatever can be done by loading an interface from a XIB file can also be done problematically. All you have to do is creating the objects yourself, setting all the properties as desired and chaining them to the desired object graph. And yes, creating UI problematically is absolutely allowed by the App Stores (for Mac and for iOS), since it does the same thing by hand as loading a XIB file does automated.

Yes, it is possible and allowed. There are very little UI related operations that can't be done programatically on Cocoa Touch.

Related

How to copy entire XCode project for another device?

Ok, I have an iPhone project that utilizes the camera.
I'm trying to utilize 80% of the same code for an iPad version of this project, however, I have to change some values as the camera quality in the latter device is messing with some parameters which I used as criteria for the first device.
So what I did was: I duplicated the iPhone project and had two targets in total, in the same project, the first one - for the iPhone (the original), and the second for the iPad.
When I clicked on the second target and added a comment on some .m file, the same comment appeared in the same .m file in the iPhone version's file too.
I don't want that - as you can see, I want a separation. I want to use the iPhone project as a base to modify the code of the iPad project. But how do I do this ? If the comment appeared in the iPhone .m too then obviously that means there is no distinction , and that whatever I do in the iPad .m will mess up the other .m ?
it looks like your two projects are sharing the same files. If you want to keep them separate, just duplicate the source files and add them back to the projects individually.
I'd create a universal app. That way you can share all of your code between the two devices in a single project. Then you can simply separate logic for each device type into different files. So for example, have ViewControllerA for both device, and ViewControllerA_iPhone and ViewControllerA_iPad for the each separate device.
Possible duplicate:
Conditional Compilation between ipad and iphone
I think you don't need a second implementation file, you just need to compile for a different device or check which one you are on at runtime and adjust accordingly.
I think don't need to copy the entire project. You can just copy the necessary files only and create logical groups for iPhone and iPad. Check the device type into appdelegate class if it is iPad then call iPad related class else iPhone. Hope it will help you.
it sounds to me like you need to 'extend' the functionality of the original to incorporate the new.
Would it not be easiest to create the 'interface' and then an base form of the class (maybe make it abstract), that implements all the methods, but leaves those that may have special needs (just have them throw an error as basic method functionality)
Then for the 2 projects you can extend the abstract class and overide the methods adding in the functionality that you require.
The beauty is that if there is an error condition in the overidden methods you can just call the 'superclass' abstract method and throw out the error message, you may decide that the super class method should take a string input variable to enable you to use a customised message taged onto the end of the one in the abstract class.
David

How do you build or modify the user interface for an iPhone App?

What application is used for creating iPhone user interfaces?
Do you write code for layout, is there a css-esque system in place etc?
Or is it more like creating a winforms application where you drop in the elements in a visual designer?
Is it difficult to modify the appearing of an existing iPhone application, say to change the graphics used for buttons, and background colours on certain screens etc?
Additonal Info
The reason I ask is that I have a Blackberry application that I want converted to an iPhone application, and I need to know if I have to tell the developer translating it to build it in a certain way, as I need to be able to change the graphical appearance of this app.
I need to be able to change any background colours, logo, and the buttons used. Not sure if the iPhone uses images for "buttons" on the GUI?
You can either create UI completely in code, or use the Interface Builder visual tool to create pre-made UI objects, or any mix of the two. You can also modify an object loaded from an IB .xib file in your app's code.
To modify stuff created in code, you would need to edit the code and recompile. To modify objects created in interface builder, you would still need to rebuild the app (assuming stock tools and OS) with those new objects.
You can use Interface Builder, something like visual designer you said, to create xib (xml based) file for the UI. You can also create UI manually by code.
If you're more familiar to using css to layout UI elements, you can make a site for safari fitting the device's resolution, or put things into a html string and load it into a UIWebView.
You're able to modify the graphics, but you cannot put the app back to your phone unless you JBed you phone.

iphone, xcode; Reverse engineer a nib

I was wondering if there is a way i can design a nib/xib file and generate code for that?
meaning, instead of writing lines of code to generate an interface, would'nt it be easier to design and nib file using IB and get the source or something?
Thanks
I think that you may misunderstand what a nib file is.
If you mean that you'd rather create your view objects in interface builder and have outlets automatically inserted into your source files then look to XCode beta, it does that.
I don't think its possible in xcode to generate code for a nib file designed.I know you are referring to web designing tools like macromedia dreamweaver.
Secondly why do you require the code?X code provides the facility to integrate the nib in the code itself.
Thanks
You are asking for a code generator, which as jsd noted IB will do if you really want.
However, your life will be a lot easier if you just accept what IB is, an object creation, placement, linking and storage mechanism.
IB is doing all the tedious stuff for you, creating instances and setting initial values for you along with (some) relationships, then compositing them all. It freeze-dries the result so it's ready to go at runtime.
It does sometime make sense to use what IB has done as a template to base other code around instead of using the views it creates directly, but if you generate code then you are potentially out of sync with IB and it makes it hard to use for maintaining the interface going forward.

How to convert nib/xib to objective C code?

I am just wondering is there a way to convert nib/xib file to ojbective C code? I just want to find the equivalent code to the nib/xib file (I've tried nib2objc, seems the result is not what I am after).
Actually I want to compile this example
http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html
without nib/xib file (I want it exactly the same with original), any idea about doing this?
Check out nib2objc:
nib2objc converts NIB files (or XIB ones) into Objective-C code, including all the properties of each instance, the documented constructor calls, and also the view hierarchy.
nib2objc yourfile.xib > code.m
In the general case, I think the answer is no. Nibs are not code; they're archives of serialized objects. So what you're asking is, "Given a graph of arbitrary serialized objects, can I generate some source code that might create such a graph without using serialization?" Without special support for such a process in all classes involved, I don't see how you could.
It would probably be more beneficial to ask about what you actually need to accomplish rather than this specific way of doing whatever it is.
To all the 'There shouldn't be any reason to not use a nib/xib' type responses here, let me provide a concrete example as a counterpoint.
[iPhone OS 3.1.3, 3.2]
iPhone OS apps have a limited amount of memory to work with. If you use too much your app is automatically terminated by the OS.
Interface builder loads images referenced in a nib/xib into a cache using [UIImage imageNamed...], which uses up memory and does not automatically release that memory. There is also no way for you to request those images in that shared cache be released.
Lay out some large images in nib/xib files (i.e. - backgrounds), in an app with multiple nib/xib files, and you will very quickly have an app which gobbles up memory quickly (3mbs per full size png background on iPad), that you have no control over releasing. Any doubts about this, check the documentation for [UIImage imageNamed] and do some googling to verify that is what is used.
That's a case for not using a xib/nib.
I think it makes sense to do this if you just want to create a starting point for a view that is created programmatically in a way that isn't easy or possible to do with Interface Builder. It is also convenient if you want to bundle the view hierarchy in to a static library so that it is fully self-contained. Ideally you want to use nibs if possible though. It will make internationalization easier. However you can still support internationalization with a strings file.

Should views be created using NIBs or code in iPhone?

Are there any performance, development drawbacks or advantages when designing views using Interface Builder?
Often you want to use Interface Builder; there are several reasons why you would want to do this over programmatic interfaces:
it is the more accepted way of creating user interfaces, due to its simplicity and visual advantages that you can't achieve as easily by simply using code.
it helps your applications to conform to the iPhone Human Interface Guidelines, through the use of the markers etc, which Apple encourage developers to follow, in order to maintain consistency and usability across iPhone applications.
Despite this, the main reason why programmatic interfaces are sometimes more favourable over using Interface Builder is for interface elements that need to be created several times - for example, creating n UIImageViews - based on a variable that cannot be replicated in Interface Builder. Programmatic interfaces allow for this flexibility and are usually more efficient in this case.
Note that NIBs/XIBs do also take up memory, and if all of your interfaces are placed in your main NIB file, it will not only increase memory usage by your application (for resources which may not be needed instantly anyway) but it will increase loading time. That being said, however, the normal workaround to this problem is not to use programmatic interfaces, but to place different groups of interface elements in different NIB files, placing the immediately required interfaces in the main NIB file, which gets loaded when the application starts, and other groups of interface elements in other NIB files which get loaded when required.
In short, the general way to go is to use Interface Builder, except for when you need to create a variable amount of elements that cannot easily be dealt with in Interface Builder.
One drawback is that it is easy to miss wiring up an outlet or action, and troubleshooting this can be painful. Two positives are that positioning, aligning, and anchoring UI elements is much, much easier, and elements redraw themselves when the phone is rotated (which is an animation process you would otherwise need to handle yourself with programmatic elements).
Speaking for myself, I found interface builder horribly obtuse when I was trying to learn how to develop for the iPhone. The workflow you're supposed to use still doesn't make much sense to me. The interface builder is faster for finicky interface layouts than hand-coding.
The disadvantage with generating the GUI programmatically in your UIViewControllers is that you've blurred the difference between Views and Controllers in the MVC pattern. If you can keep the GUI generation to the loadView method, you can still keep a decent boundary between code the generates information and code that displays information.
In short: I much prefer generating GUIs by overriding loadView in the UIViewController subclasses.
Why did nobody mentioned translation. We have a project in 11 locales - this will give a number of nib*(#locales) - it's just not acceptable (more than a hundred nibs for a project of 10 UIs).
From what I've seen until now, generating views with XIBs is VERY easy. But since I've not been developing on iPhone a long time, I can only direct you to this article that shows a sample XIB converted to Objective-C code.
http://arstechnica.com/apple/guides/2009/04/iphone-dev-convert-xib-files-to-objective-c.ars
Interface Builder anyday! :)
I'm sure there are no significant performance gains by directly coding the view.
Never look at the Code generation of NIB using the tool. But look at the Note by apple.
Note: Although you can create an Objective-C application without using nib files, doing so is very rare and not recommended. Depending on your application, avoiding the use of nib files can involve overriding large amounts of framework behavior to achieve the same results you would get using a nib file.