I am primarily a web developer (ruby, python) that is new to iPhone development. I've done some desktop development in the past within the MS environment (C#), but never anything on the mac.
I'm trying to build a really simple iPhone application and 开发者_开发知识库I am confused by the way that views work in general. If someone can provide advice for my particular problem, along with some resources where I can learn how to architect iPhone views in the future, that would be awesome. I feel like a lot of the Apple documentation that I've come across is too specific - I am lacking a fundamental understanding of how views work on the iPhone.
My particular problem looks like this:
I need one view that displays some downloaded text content. This is the view that shows when the app loads, and it is pretty straightforward.
Then I need a settings area (I've already decided I don't want to use the iPhone settings area). The settings area main page will have some text fields on it. It will also have a 2-row grouped table. Each cell in that table will take you to another view which also has a grouped table used for multi-select. I suspect that I can reuse the same view for these two final "detailed setting" views.
In summary:
- home page
- settings main page
- detailed setting 1
- detailed setting 2
Any help and advice appreciated.
It sounds like you already have a good idea of what you want each of your screens to look like; that's a good place to start.
What you're probably going to want to do is use Interface Builder to lay out the objects in each view (textfields, buttons, etc.), and then have a custom View Controller (subclass of UIViewController) for each view. You would then navigate to a new view by doing something like:
MySettingsController *controller = [[MySettingsController alloc]
initWithNibName:@"SettingsView" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
(assuming a navigation-based app).
If you haven't yet, I recommend reading Apple's View Controller Programming Guide
Some advice: Despite your back ground, don't think of the views as pages or the app as a web site. That will cause you problem in your design because the technology is different and views don't work like web pages and apps don't work like web sites.
The major difference is that while web pages often contain actual data, views do not. The view object is only concerned with display. It doesn't know what it is displaying and it doesn't store or logically manipulate the data. The data comes into the view from the view controller which itself gets it from the data model.
See Cocoa Core Competencies: Modal View Controller
Rails uses MVC if you've used that with Ruby. The basic principles are the same.
Well, there are plenty of information on Apple developers' pages: you could start reading Your first iPhone application
There are quite a few good sites with very good info both on cocoa and iPhone developing:
- Cocoa with love
- iCode blog
and many more (google is your friend in this).
A couple of books I liked are "Beginning iPhone3 Development" and "iPhone developer cookbook". The first is probably more useful at the beginning (no pun intended)
As for the specific case of yuor application, you could use a navigation controller for the settings page, and each time you need to dive into the details you will just push the right view onto the navigation controller's view stack.
So you would design 4 views with the interface builder
- Main view
- Settings view
- Detail 1
- Detail 2
And then push the views onto the navigation controller.
It's pretty straightforward, I won't go into the details, but just searching something like "iphone navigation controller example" on google will give you plenty of samples that you can easily adapt to your needs.
These were all helpful responses, in particular the reference to the iPhone View Programming Guide. This helped me to diagnose my misunderstanding which was related to the role of View Controllers, and the relationship between individual views and view controllers. I think part of my confusion came from learning MVC in the context of Rails, where this relationship is quite different.
For others looking for advice in this general area, I would recommend checking out Lecture 6 from Stanford's iTunes U iPhone Application Development course from Winter 2010 "Designing iPhone Applications, Model-View-Controller, View Controllers", and the lectures 5 & 7 if you have time. I think that was when the penny dropped for me, despite having already looked at a few of the books mentioned here.
精彩评论