UITableView theory help for a grizzled old web developer - iphone

I am a web developer who is trying to transition to Objective-C and Cocoa-touch. I am used to creating a table as a Dom element and then inserting it. If I wanted a link I did that as I went along. Obviously iPhone development is very different. I am looking for either a good explanation of hOw to wrap one's mind around the cocoa way of doing things.
Specifically I am looking to pull data from a web service and then make a drill down 3 or 4 levels deep. If there is a tutorial that shows how to do that perhaps I can learn through that.

Take a look at Apple's SeismicXML sample code. There's a lot in there, but it's basically what you asked for: an example of grabbing data from a web service and displaying it in a table.
There's a pretty big difference between creating a table on a web page and creating one in an iOS application. In the first case, you're actually writing down the data that gets rendered into a table by a browser. In the second case, you're creating a table object, and that table is like a living, breathing (compared to a web page, anyway) thing that can change through it's lifetime. The table will ask your code for data to display, and also what to do at certain points, such as when a user taps a cell.
Looking at a sample like SeismicXML is a good idea, but you'll still be mystified if you don't take the time to really understand what's going on. (I'm not saying you wouldn't, but there are plenty who don't and are confused to this day.) Go look, and then come back here if you have more questions.

The paradigm for iPhone tables is very different from HTML. On the web, you build the table and its elements and insert them into the DOM. On the iPhone, you have a proxy object that answers questions as the table builds itself. The table will ask the delegate how many entries it has and what it should put in each entry. That way, the delegate only needs to look up the information that is currently needed by the table, and not the whole thing, which may be only partially displayed. For instance, the delegate might to database queries as needed.
The simplest way is for your delegate to grab the info it needs from the web site and store it in an array for when the TableView asks for it.
The TableView itself is placed on the screen by calling addSubview: on a parent view.

You're asking more than one question here. You should split them up into multiple, more specific questions.
There are a variety of ways to make HTTP requests, anywhere from using the bundled classes like NSURL to using external libraries like ASIHTTPRequest. It also depends on what kind of data you are getting from the Web service -- there are various libraries to parse XML and JSON.
To make a "drill down" I assume you are describing table-based navigation. There are dozens of examples in the Apple sample code archive of projects showing off how to use UITableViewController, and probably hundreds available on Stack Overflow.

Related

How to set up an iOS app to have perpetual memory?

I am asking what code to use to save user data in the app so that it is perpetual, even after the app is closed and reopened. I watched a few videos but my code isn't working.
I'm not interested in fixing code, I want to understand the process so I can reapply. Can anyone help me to understand how to do this and explain it in a way that makes sense for long term app development.
It will differ by application, depending on how much data and how it's organized.
If it's simple stuff, look at NSUserDefaults. If it's complicated and represented as objects, look at Core Data. If there's a lot of it and you see it as table rows rather than objects, you can use the sqlite3 database directly. If it has to be shared with other users or by other apps, start thinking about an external server or "the cloud".
There's no single right answer but those options should get you thinking about requirements.

Alternate between different views using Objective-C

I am preparing an iPad app using, obviously, Objetive-C and wich tries to deploy Data Base stored content inside a view.
Now comes the problem, it will be a huge amount of records to be shown, each of them deployed inside some kind of "container" inside the view so that I was considering to make a page browser and in every page I go to change the view I apply.
Take for example, I show the first 5 items using example1.xib, for the next 5 example2.xip and so til getting to the page 10 and starting again with example1.xib.
My question is how this can be achieved? Maybe storing diferent view class based objects inside an array and alternating them or so...
Any help or hint would be greatly apreciated.
Cheers!
Always assume others have made similar apps before you. Perhaps not exactly the same ones as you, but doing similar things that you can learn from. The iPod and Spotify apps navigate large amounts of data using indexed, searchable TableViews. Go hunting on App Store for apps that have the same kind of functionality as yours, and test them out and grab what's good and discard what's bad about them.
My advice is to get hold of a nested tables example using the built in SQLite, and go from there. I've no idea what your database looks like, but with a bit of luck you could adapt example code and just open (a converted) SQL database.
Most users by now are used to the drill down paradigm rather than the paginated paradigm, so it's worth checking out the Drill Down example that comes with XCode even if it's not for databases (at least I don't think it is, I learned from a book, like Manuel.)
I would subclass UIViewController or UITableViewController depending on what type of records you plan on using.
I would recommend checking all the Apple's Examples, and most of the available online tutorial
Here are some, may be old though...
http://www.edumobile.org/iphone/iphone-programming-tutorials/tabbarcontroller-with-navigationcontroller-and-tableview-in-iphone/
http://www.aboveground.com/tutorials/adding-a-uitableview-to-a-custom-uiview
http://www.icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/
http://blog.webscale.co.in/?p=150
http://www.ioschef.com/2011/03/un-aperitivo-de-uitableview-y-uitableviewcontroller/ in spanish..
http://adeem.me/blog/2009/05/19/iphone-programming-tutorial-part-1-uitableview-using-nsarray/ with videotutorial

Create an 'order' file on iPad/Objective C w/ auto mailer

I'm currently designing a restaurant based menu system of iPad with the basic functionality of being able to view items on the menu, then add them to an order, be able to review the order (with the possibility of removing them) then finalising a price and (time permitting) be able to email the order to a specific email address.
Currently I have a split table view with each section of the menu, pictures and text. I am at a roadblock where I can't see how I can proceed with the project.
Firstly, if I have an 'add to order button' underneath the item description, how can I create a new list (or order), how do I display it/edit it?
I'm really stuck as I see no logical way to do this.
Any help or pointers would be greatly appreciated.
I'm not sure of your mileage with the Cocoa APIs, but it sound like you are missing some fundamental knowledge about how to effectively work with them. Primarily, I am speaking about the contents of the Cocoa Fundamentals Guide, Model-View-Controller Design Pattern section.
To me, it sounds like you have made good progress on getting the view component of that design pattern, and you are at the point of fleshing out the model and the controller. If you don't understand the terminology, the model essentially encapsulates all of the objects that constitute the domain, which in your case is is "restaurant-based menu systems". Then, the controller piece is concerned with shuffling data from your model to your view and also other general application logic.
Without further requirements about what type of data your app should be concerned with, it's hard to advise you on what you need. You probably want a set of objects that align with the nouns (like Menu, MenuItem, Order, etc.). Then, those objects would have methods that determine how they interact with each other.
Lastly, the controllers (of which you should already have some in your project if you used the Xcode templates) should have a way to manipulate the aforementioned model objects and present the data. The list you mentioned could be something as simple as an Order object which has an NSArray of MenuItems that have been ordered.
So, ultimately my advice would be to read through the Model-View-Controller section in the Fundamentals guide and once you understand it, try creating a model that supports what it is you are trying to achieve. Diagrams or sketches that depict the objects and their interaction help with this. Then once you have done that, you can start to wire your model up with your interface in the controller. Hope this helps.
There are a few things you are asking here:
Adding an item to an order. This implies a purchase cart like solution. These can be quite complex. I'd start with a simple list (NSArray of item numbers?).
How to display this list. This would be the visual aspect of the cart. Just think of this as a menu table like you currently have, but with the cart array as a filter.
Emailing this information. This is surprisingly easy. Present a modal MFMailComposeViewController after adding a text version of your order as the messageBody.
A further idea would be to expand the cart to use menu item objects that you design in core data. You might also have luck hunting around for a library that encapsulates the needs of the cart for you.
Hope that helps.

iOS Application partitioning / MVC

I've been playing around with iOS development and I'm getting to the stage where I want to create something beyond a simple app. However, I'm not confident that I understand how to partition an application correctly.
For the purposes of simplicity, imagine a (very) simple audio player application. Let's say there are two view controllers, accessible via a UITabBarController which is instantiated the main AppDelegate class.
Each of these view controllers has the following responsibility:
PlayerViewController - A sound player which plays the “current” audio sample when the user presses a button.
SelectorViewController - A sample selector, that uses a UIPickerView to display the available audio samples so that the user can select which sample they want to play.
So far, so good. However, what I don't quite understand is where I should store the data on the available samples, so that both of the views can find out information on the available samples, trigger a sample to play, etc.
As both view controllers need to access this “model level” information, would creating an “audio manager” singleton class be a sensible approach, or is there (much, much more likely I'm guessing) a better means of solving this problem that I'm overlooking.
Any pointers would be much appreciated.
I've used this pattern (Singleton data manager) several times in serious apps. It's quite straightforward, easy to understand, easy to use, although this pattern is despised by OOP purists.
If nobody tells you it's wrong to use a singleton, go ahead, just be sure to check Apple's documentation on the recommended implementation (there is a bunch of methods to overload).
Oh and BTW, Apple uses it a lot in the iOS SDK, so it's a common practice (see class methods beginning with 'shared').
UPDATE:
Another possibility is reusing an already existing singleton, the Application delegate for instance. It might feel cleaner, or not, it's more a matter of taste. It has the advantage of giving a clear "entry point" where you allocate/create/init your data manager.
If the source of your data is in a remote server and it comes to your app as an XML file, you can also get it whenever you want with a kind of source downloader class.
That way you don't have to care about keeping things in memory when they are not necessary. Just get it from the remote source, parse it and then release it.
Another way of achieving this more careful use of memory is to get your data from a sqlite database using Core Data. But some people thinks it is too much complicated for a simple app and prefer running queries by hand.

UIWebView - How does tabbed browsing work?

I've a noobish question. How does tabbed browsing work? I mean that you save the current webView with it's content in an array and show it later.
like you can read here http://www.iphonedevsdk.com/forum/iphone-sdk-development/24521-please-need-help-webview.html I made few attempts but no luck so far.
as anyone a nice suggestion? Thanks in advance
Implementing a tabbed web browser is more of a design challenge than a pure programming challenge. You need to consider how the user will switch between different tabs. From a data structure perspective, you can store multiple instances of UIWebView in an array, as you mention.
From a design perspective, you should look at the way Apple implements their web browser. Their approach seems to be more of a multiple window system than a multiple tab system.
One thing to keep in mind, UIWebView's use a lot of RAM, so be careful keeping too many stored in memory.
PS: if you are interested in checking out a tutorial on UIWebView check out this tutorial