building a dynamic UI in iphone - iphone

How hard is it to create a UI, which views is based on the data that a user has?
So say I can have a scroll view, and a particular user A can have a view which consists of X,Y,Z and user B can have a view which consists or Y, Z? I am just concerned about positioning the views in a views because we can't do that now via interface builder and it needs to be coded.

You can build an entire app with multiple views and controls without touching Interface Builder. The UI views and elements can all be allocated and configured programmatically.
Apple even has a WWDC 2010 video on how to build data driven app UIs.

In case anyone else is looking for Data Driven UI information the WWDC post from WWDC2010 is at about 40-41minutes in the Game development video part 1 (Video 401).
Other than that there is not a lot of information on data driven UI for Objective-C. I am about to add it to an existing project because we need multiple layouts for the same screen and i found it hard to just switch the view based on the layout (wrecked the bindings from memory).
Shouldn't be too hard though, simple framework to load the plist and use KVC to set all the values.
If people are new to KVC i would recommend adding the following method to stop errors happening when you set keys that don't exist, esp. if non-programmers are going to do some of the layout.
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
NSLog(#"The key %# does not exist.", key);
}

You can either do a callback-based approach like UITableView, i.e. -cellForRowAtIndexPath, or a more explicit setter like UIMenu where you set the items.
For the latter approach, have a -setObjectsArray: or similar method where you configure your subviews according to the input data, i.e., make sure you have three of them if you have (x,y,z) and set their data to 0th view = x, 1st view = y, etc.
Next override -layoutSubviews and set the frames of each of the views based on their position in the order and your bounds.
Does that help?

FYI: It's session # 117: "Building a Server-Driven User Experience"
You can find it through iTunesU:
Search for WWDC2010
Go to "Application Frameworks"
Get "Session 117 - Building a Server-Driven User Experience"
The link to the PDF slides is on the page: WWDC 2010 Session Videos
Ray

Related

Mouse Move and ViewController

In order to understand the basic concepts I develop a simple Mac OS X application to calculate fractals. The application is a simple window app and has a class that calculate the fractal, and a single window in which there are:
a custom view for showing the image.
some controls for select calculation parameters. These controls are
connected with the appdelegate.
Everything works fine, but :
I would like that when the mouse is over the view with the image,
some text fields report in real time the coordinates. What i have to
do to realize that ?
I suppose that the connection I have done with the app delegate
is not the best solution.
Is it better to define a custom view controller? If so, how can I do to introduce a custom viewcontroller using interface builder?
You can just track the Mouse Events MouseMoved
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html#//apple_ref/doc/uid/10000060i-CH6-SW1
Then you might be able to do this:
NSPoint location = [renderView convertPoint:[theEvent locationInWindow] fromView:nil];
Then you will get X and Y relative to the view containing the image.
be careful of reading the apple documentation or you might miss things like:
Note: Because mouse-moved events occur so frequently that they can
quickly flood the event-dispatch machinery, an NSWindow object by
default does not receive them from the global NSApplication object.
However, you can specifically request these events by sending the
NSWindow object an setAcceptsMouseMovedEvents: message with an
argument of YES.

best way of dealing with layers of images / views for an iphone app

If i wanted to create a system whereby you could display a little rectangle ON TOP of an app already running, in which I could put any number of things, what would be the best, most apple standard way of doing it?
I'm thinking of something similar to iAdd. basically layers of views I suppose. I know that microsoft has a standard war of coding game menus for example. they're layered - each one has various event handlers for when things start and finish and they're own little update / load / draw methods etc that get called when appropriate. is there something similar for apps?
The most important thing really is just the starting point. what should I be doing in order to create another view over the existing one?
All UI elements in iOS inherit from class UIView. To add one view inside another use [view addSubview:subview]
For detailed information about how to use the UIView class, see View Programming Guide for iOS

Programmatically Code a UITableView for iPhone Application in Xcode 4.2

I have been working in Storyboards for a while now and they are perfect for smaller apps. But I'm trying to put together a collection of 40+ recipes so it's unrealistic for me to drag 40 different Detail Views onto the Storyboard!
I'm wondering how can I programmatically build a table view with 40 different rows that each lead to the same Detail View, but pull different content? Thinking of storing the content in an array and based on which table cell the user clicks we pull from a different index in the array. So for example if the user clicks on recipe #2 in the table it will load a generic Detail View which populates its data from my array index #2.. Please ask for clarification if I'm not making any sense.
I've looked through the Apple docs and a lot of their tutorials reference Core Data which I would like to not use... I don't think it's required for iOS 5 and there must be an easier way than using Storyboard to drag-and-drop 40 different Detail Scenes.
Your question is at a very high level so I can't provide much help other than to provide guidance. Your idea in the second paragraph sounds exactly how you should write your application in iOS.
You build a model containing your recipes (CoreData or other store)
Link this to a navigation controller hosting a table view controller (NSFetchedResults controller or your own code or a combination of both)
A selection in the table view pushes the (generic) detail view controller onto the Navigation stack (using the push segue is probably easiest)
The detail view controller populates itself (with the detailed recipe instructions) using a unique name that you pass to it that will enable it to load the detailed recipe from your data store
In fact, I believe that Apple demoed an example app that did exactly this during either WWDC
2010 or WWDC 2011.
If there's any section you are not clear on, post a new question detailing what the problem is, what you've tried so far and/or what your errors are.
Hope this helps.

Changing views iphone

this is a very noobie question although I have had quite a bit of experience iphone development.
I have a client who wants an app with various screnns, but does not want to use built in iphone navigation, but instead wants to have buttons on the screens. All I can find is a load of 14 year olds giving tutorials on MVC or using different views in the same nib.
Does anybody know what apples suggested way of doing this is as I can imagine it been a mind field.
Many thanks
Maybe you should have followed the MVC tutorials of the 14 year old guys.
Then you would know that you could use the built in iphone navigation controllers (ie UITabBarController, UINavigationController) without their standard view counterparts (ie UITabBar, UINavigationBar).
You could always just draw buttons on the screen in interface builder and use custom images for the normal/highlighted states.
When the button is pressed it's up to you what you'd like to do with the received buttonclick method being invoked... the usual way is with the standard navigation system which can optionally have a navigation bar at the top with (back) button, title, etc... and you push/pop viewcontrollers in a hierarchical way. You can just turn the title (or change for your own style) but it does enforce a hierarchical structure.
If you don't want hierarchical navigation of your screens you can either do this with your own custom navigation controller than handles which viewcontroller is currently visible or you could use a thirdparty component like three60 which allows you to navigate around like a webbrowser does on webpages.
You may also want to take a look at Corona which is more for games but would allow you to do a totally custom interface with all sorts of custom transitions and just needs you to write lua... that said it will limit you on using their engine with this approach as you can't get to the ObjC level.
Finally one last approach is simply to use webview and pick up the clicked links so you design your app via webpages... rather ugly approach but can work well if you're very familiar with HTML.

iPhone Development: What's the difference between an View-Based Application and an Window-Based Application?

Like I understand, an Window has a lot of Views. A View is an object that can draw something on the screen, and the Window provides the space for drawing. So where's the point, that I dont have an window? What's the difference here between them?
On the iPhone, a window really is just a special kind of view. If you look at the docs for the UIWindow class, you'll see that it has additonal methods above and beyond what a regular UIView has. However, most of those methods seem to have analogous UIView counterparts.
The one thing I've found windows useful for is that UIViews have a "window" property that can be used to instantly access the window. If you have many nested views and need to immediately get to the top level from a 3rd or 4th level deep view, that window property can come in handy.
In a View based application we can create the foreground layout and the appearance of the application including text fields,buttons,labels..... depending upon the requirements of the project and how effective an application view has to be in order to make the application shine
In a Window based application we have the background of the view and we can also create a view using a window by using Interface Builder connections.But for building applications that work basing on the background we need to have Window based applications that runs on the console.