又拍网 for iPhone v1.0

2011年1月30日 05:47

 

http://itunes.apple.com/cn/app/id414458293?mt=8

又拍网(Yupoo.com), 就是这样, 为你拍照而生, 为你的快乐而生, 为你的感动而生


我们想把又拍网(Yupoo.com)建成你最喜欢的照片分享生活社区。你可以在又拍上和家人朋友分享拍照的乐趣,回忆照片背后的感动;你可以在又拍上找到志趣相投的新朋友,闲聊生活的美好。

又拍网全力以赴的,是让你能够轻松地发布你的照片,把你的感受传递给朋友、家人、可能会成为朋友的陌生人。你只需要按下快门,想着拍出可爱、有趣、感动的照片,复杂的后台问题我们来帮你完成。

 

 

 http://itunes.apple.com/app/id401431381?mt=8

 豆仁及豆瓣人,是通过豆瓣网开放的API开发的一款iphone软件。

主要功能包括联系人最新广播、同城活动、用户/活动/书籍/电影/音乐的搜索、收发豆邮、个人活动/日记/收藏/评论等。

豆瓣API目前没有提供没有小组的API,所以此软件没有小组功能!

豆瓣群:http://www.douban.com/group/douren/

优酷视频:http://v.youku.com/v_show/id_XMjI2MzM1NTYw.html

 

 

驾驶题库 1.2 发布

2010年2月04日 06:53

Drive Theory:http://itunes.apple.com/cn/app/drive-theory/id352262329?mt=8

本软件是帮助大家学习驾驶知识的小工具,旨在帮助学习驾驶以及需要了解驾驶知识的朋友。 如果你对本软件有好的意见或建议,请告诉我们,以便我们更好的为您服务。

 

 

SortUsingSelector

2009年12月28日 22:41

 The original paper comes from: http://www.cocoadev.com/index.pl?SortUsingSelector

sortUsingSelector is an instance method of NSMutableArray


What should the structure of a function be when it will be called by sortUsingSelector:?

The method selector you pass in should specify a method that returns an NSComparisonResult? (either NSOrderedAscending?, NSOrderedSame?, or NSOrderedDescending?), just like the compare: method that everything responds to. If your NSMutableArray is full of NSStrings? or NSNumbers?, you can just do:

[myArray sortUsingSelector:@selector(compare:)];

and it will sort them appropriately because NSString and NSNumber both properly implement compare:. The idea is that every class should implement a compare: method that makes the receiver compare itself and return the right result.

sortUsingSelector: gets more interesting when you have objects that aren't simply strings or numbers. For instance, let's say I have a class Person with instance variables (and corresponding accessor methods) firstName and lastName whose objects I want to be able to sort by name (in the form "Last, First"). I can implement something like this:

- (NSComparisonResult)comparePerson:(Person *)p
{
    return [[NSString stringWithFormat:@"%@, %@", 
                                       [self lastName], [self firstName]]
            compare:
            [NSString stringWithFormat:@"%@, %@", 
                                       [p lastName], [p firstName]];
}

 Using this method with sortUsingSelector: will sort all Nelsons before all Smiths, and Abby Smith before Bernard Smith.

Of course, you can make things more flexible by deferring the sort order until runtime. Sometimes you may want to sort by first name instead of last name. In this case, the best thing to do is probably something like this:

- (NSComparisonResult)comparePerson:(Person *)p
{
    return [[self stringForSorting] compare:[p stringForSorting]];
}

- (NSString *)stringForSorting
{
    if (something)  // determine sorting type here
        return [NSString stringWithFormat:@"%@, %@", 
                                          [self lastName], [self firstName]];
    // else...
        return [NSString stringWithFormat:@"%@ %@", 
                                          [self firstName], [self lastName]];
}

You would replace the "if (something)" condition with something useful; maybe check a user preference, or the state of something in the GUI.

-- JackNutting


Is this any different from sortUsingFunction? They seems just about the same, except with different paramaters

It is similar, but there is one important advantage to -sortUsingFunction:context:, it allows you to send in a "context" pointer, which allows you to build a sorting function that accepts some info to help control the sorting. This can be a pointer to anything at all, but in practice I find it most useful for sending in an NSString that will specify a method to base the sorting on.

To extend our previous example: We had set things up there so that the Person object could control the way the sorting was done (lastname or firstname). Let's say that we want that control to happen not in the Person class itself, but in the "user" of the Person (perhaps we've got a PersonListView?) or something).

To do this, we can implement a sorting function that accepts a "context" paremeter that allows us to specify the method used to determine sort order for the objects we're looking at. For example, we might like to be able do things like:

[personArray sortUsingFunction:comparePersonsUsingSelector
                       context:@"lastName"];
[personArray sortUsingFunction:comparePersonsUsingSelector
                       context:@"firstName"];

In this case we're passing in an NSString as a context to tell our function the name of the method that should be used for sorting. The function implementation would then be something like this:

static int comparePersonsUsingSelector(id p1, id p2, void *context)
{
    // cast context to what we know it really is:  an NSString
    NSString *methodName = context;
    SEL methodSelector = NSSelectorFromString(methodName);
    id value1 = objc_msgSend(p1, methodSelector);
    id value2 = objc_msgSend(p2, methodSelector);

    return [value1 compare:value2];
}

Note that in real code you'd want to have some error-checking here, for example making sure that the "context" passed into the function is really an NSString, making sure that p1 and p2 both respond to methodSelector, etc.

The extra functionality you get with -sortUsingFunction:context: could easily be provided in a method-based form by implementing something like -sortUsingSelector:context:; why Apple didn't include it is a mystery to me. Maybe as an "exercise for the reader"?

--JackNutting


A simplification of the example above: pass a SEL as the context, instead of an NSString *. I've also used -[NSObject performSelector:] instead of calling objc_msgSend() directly.

[personArray sortUsingFunction:comparePersonsUsingSelector
                       context:@selector(lastName)];
[personArray sortUsingFunction:comparePersonsUsingSelector
                       context:@selector(firstName)];

static int comparePersonsUsingSelector(id p1, id p2, void *context)
{
    // cast context to what we know it really is:  a SEL
    SEL methodSelector = (SEL)context;
    id value1 = [p1 performSelector:methodSelector];
    id value2 = [p2 performSelector:methodSelector];

    return [value1 compare:value2];
}

 -- Greg Parker


Advanced Sorting Techniques

Let's say you've got an array of animal objects. Each animal can be a Dog, Cat, Bird, or Fish. Now, you want to keep them sorted by kind, but within each group, you want them sorted by name also. Here's a sort method for doing something like this:

// example enum
typedef enum
{
	AnimalDog,
	AnimalCat,
	AnimalBird,
	AnimalFish
} AnimalKind;

// example class interface
@interface Animal : NSObject
{
	NSString *animalName;
	AnimalKind animalKind;
}
- (NSString *)name;
- (AnimalKind)kind;
@end

- (NSComparisonResult)compare:(Animal *)otherAnimal
{
	// comparing the same type of animal, so sort by name
	if ([self kindOfAnimal] == [otherAnimal kindOfAnimal])
		return [[self name] caseInsensitiveCompare:[otherAnimal name]];
	
	// we're comparing by kind of animal now. they will be sorted
	// by the order in which you declared the types in your enum
	// (Dogs first, then Cats, Birds, Fish, etc)
	return [[NSNumber numberWithInt:[self kindOfAnimal]]
		compare:[NSNumber numberWithInt:[otherAnimal kindOfAnimal]]];
}

Aarrgghh. Excessive object orientation alert. Creating two NSNumbers from your ints and then sending them a compare: message is a rather baroque way to find out the ordering of two integers.

NSMutableArray 排序

2009年12月25日 05:17

原文来自:http://iphone.ipsw.info/2009/10/nsmutablearray.html

 - (NSArray *)sortedArrayUsingSelector:(SEL)comparator

Parameters
comparator

A selector that identifies the method to use to compare two elements at a time. The method should returnNSOrderedAscending if the receiver is smaller than the argument, NSOrderedDescending if the receiver is larger than the argument, and NSOrderedSame if they are equal

 

NSArray *sortedArray =
    [anArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

 

 


@property (nonatomicreadwriteretain) NSMutableArray *parameters;

 

[self.parameters sortUsingSelector:@selector(compare:)];


 

 

#pragma mark -

 

- (NSComparisonResult)compare:(id)inObject {

     NSComparisonResult result = [self.name compare:[(MPURLRequestParameter *)inObject name]];

     if (result == NSOrderedSame) {

result = [self.value compare:[(MPURLRequestParameter *)inObject value]];

     }

 

      return result;

}

 

//////////////////////////////////////////////////////////

 

sortedArrayUsingFunction:适合基本类型(支持compare方法)

#pragma mark SORT METHOTDS

NSInteger sortObjectsByLatestTime(id obj1, id obj2, void *context)

{

 

NSDate* d1 = [(MessageGroup*)obj1 latestTime];

NSDate* d2 = [(MessageGroup*)obj2 latestTime];

//sort by desc

return [d2 compare:d1];

}

 

NSInteger dateSort(id obj1, id obj2, void *context)

{

NSDate* d1 = ((Inbox*)obj1).datetime;

NSDate* d2 = ((Inbox*)obj2).datetime;

return [d1 compare:d2];

}

////////////////////////////////////////////////////////////////////

 

 

-(NSArray*)sortedMessages

{

return [[groupMessages allValuessortedArrayUsingFunction:sortObjectsByLatestTimecontext:NULL];

}

//////////////////////////////////////////////////////////

sortUsingDescriptors:适合元素是dict类型,initWithKey既是dict key.

 

NSMutableArray *regions = [NSMutableArray array];

 

 

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor allocinitWithKey:@"name" ascending:YES];

NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

[regions sortUsingDescriptors:sortDescriptors];

[sortDescriptor release];


May How to Get Started with iPhone Dev

2009年12月24日 00:40

 

The Original paper come from: http://www.webdesignerdepot.com/2009/05/how-to-get-started-with-iphone-dev/

 

 The iPhone is a fantastic phenomenon. It’s a communications device, a multimedia platform and much more all rolled into one single tool. Everyone wants in on this device.

 

The Apple store has just passed the one billionth application download (I alone account for 3% of that…) and there is a wide array of applications from the amazingly useful to the bizarrely redundant.

With millions of iPhones out there, it makes sense to have your content, or application available on that platform, but how do you go about doing this? Where do you go to get started? And what are the steps you need to take to get there?

This article is an introduction to the various ways of getting content and applications onto the iPhone. It is by no means a full guide, but hopes to point you in the right direction and give you an overview of what is involved in the process.

Immersion

The first step in writing for the iPhone is understanding how things really work on the iPhone. I think it is virtually impossible to develop for the iPhone without being a solid user for a while.

The iPhone has a certain way of doing things and if your content does not adhere to that it will stick out like a sore thumb. It is very different to what happens on a desktop.

The only means of interacting with content on the iPhone is your fingers. This dictates a lot of the way the interface works. The other major differences are that the screen is small, only one application runs at a time and there is very little opportunity to provide user help.

The iPhone uses animation extensively to provide a fluid, responsive interface that feels almost physical (as if the screen’s contents are really moving off, jumping or collapsing). You really need to get a feel for this to be able to create something that lives comfortably on the iPhone.

You could potentially use the iPhone simulator on a Mac instead of an actual iPhone or iPod Touch, but… that doesn’t really do it. The iPhone has a set of accelerometers that can sense the orientation and movement of the device. You really need to hold it and feel it.

Apple provides a wealth of information on its iPhone developer site: 
http://developer.apple.com/iphone/

There are introductory videos, documents and sample code. Besides all the introductory material, a great document to start with is the iPhone user interface guidelines.

They can be found here:http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/MobileHIG.pdf

I highly recommend starting out with this document. It has examples and sets you out on the voyage. Familiarize yourself with the way things are done on the iPhone and the arsenal of controls and functionality at your disposal.

 

Planning

I’m not going to go deeply into this. Planning on the iPhone is like planning for any other platform.

You need to be clear about what you want to achieve and explore what functionality you want to expose with your project. Strive for a solution that is clear, understandable, visually pleasing and of course… cool.

 

Visualizing

Once you know the game plan the search starts for the design. With the unique iPhone look, it is essential that you use that look in visualizing your project’s interface.

Recreating the iPhone interface for wireframe or sketch purposes is a lot of work. Fortunately people have already put in that effort and it is available for you to use.

These are collections of graphical widgets in various formats that can be used to assemble what looks like iPhone screens. You can use them to put together sketches and wireframes for your projects. Here are a few:

Yahoo Design Stencil Kit

Part of the Yahoo UI Kit. This is an excellent resource for any kind of UI design visualization. The Yahoo! Design Stencil Kit version 1.0 is available for OmniGraffle, Visio (XML), Adobe Illustrator (PDF and SVG), and Adobe Photoshop (PNG). It is a set of graphics in different formats to be used in various applications and help you put together UI sketches.

Download here: http://developer.yahoo.com/ypatterns/wireframes/

 

Geoff Teehan’s iPhone GUI

A Photoshop file that has a fairly comprehensive library of assets, some editable

Download here: http://teehanlax.com/downloads/iPhone_GUI.psd.zip

 

Sketch paper for the mobile designer

A PDF or Photoshop based ’sketchepad’ for sketching out iPhone interfaces.

It can be downloaded here: http://labs.boulevart.be/index.php/2008/06/05/sketch-paper-for-the-mobile-designer/

And of course, there are several others floating around.

OK. So now you have an idea or some content, you thought of the game plan, you sketched out an interface that would look at home on the iPhone. What’s next? Well…there are several approaches you can take to get your project on the iPhone:

 

Do Nothing

The iPhone has a remarkable web browser for a mobile device: Safari. It has a few tricks up its sleeves and does its best to present any website in a readable fashion. So… if you have a website that is up and running, you might get away with doing absolutely nothing.

Safari is able to present nearly any website in a readable way. The user can double click on any section of the web page and Safari will zoom in to a readable scale and present that page.

Things that are to be avoided for iPhone compliance are:

  • Flash. There is currently no support for Flash on the iPhone
  •  Segments of the site that rely on mouse hovering. Since there is no mouse, or cursor, the hover event is never triggered and therefore any behavior you designed will never show on the iPhone.
  • Wide, rigid layouts with no columns. iPhone does not handle those well.

So if your site/app works well with Safari on the iPhone with no changes, that is your path of least resistance.

 

Do a little

The next step up is to keep your site, but make a few adjustments, so that viewing it on an iPhone will be a better experience for your visitors.

Here some some simple tips and trick that will make your site work well for an iPhone visitor.

  • Use columns. This is quite basic but it makes a huge difference. Users will double click on a column and will be able to zoom in and read your content easily.
  • Organize complementary information so that it is placed in the same column. That way the user can read a whole chunk of related material by scrolling, without having to hop around.
  • Don’t use absolute font sizes. Use percentages instead.
  • Use the metatag. This is the most fundamental concept in any iPhone web work. It defines the size that the page should be resized to before scaling it down to fit the iPhone. it takes the format of
  • Read Apple’s guide for iPhone web sites over here:http://developer.apple.com/safari/mobile.php

Develop a site for the iPhone

Now you’re talking! You are going to develop a website specifically for the iPhone. You need to learn what is possible from here http://developer.apple.com/safari/mobile.php and start putting it all together.

The idea is to build a web app that lives comfortably on the iPhone, preserves the visual style and behaviors the iPhone users are used to and takes advantage of the special features of the platform such as gestures, orientation changes, etc.

You don’t have to start from scratch. There are plenty of great resources that provide a good starting point or framework to build your iPhone:

  • iUI: Allows you to create navigational menus and iPhone interfaces, with a minimal knowledge of JavaScript. It provides an ability to handle the phone orientation change and an experience that is more iPhone like. iUI is a library of JavaScript and CSS that is intended to mimic the look and feel of the iPhone on web pages.http://code.google.com/p/iui/
  • Webkit: Safari is a webkit based browser. Webkit adds a whole lot of functionality that takes advantage of unique iPhone features (database accessible to your app, understanding iPhone gestures, orientation sensing and much more) check it out here:http://www.westciv.com/iphonetests/
  • Aptana Studio: An IDE that includes an iPhone site project starter. It contains management of phone orientation and other goodies. It will even preview your site in a mock iPhone screen: http://www.aptana.com
  • jQuery plug-in for the iPhone: jQuery is a lightweight, surprisingly powerful JavaScript library. Jonathan Neal created a jQuery plugin for the iPhone which helps you put together an iPhone centric web app. http://plugins.jquery.com/project/iphone

 

Using the Aptana Studio iPhone template / Code view

 


Aptana Studio showing iPhone preview

 

Various sites developed specifically for the iPhone

 


Various sites developed specifically for the iPhone

 

The following options involve the Apple Developer tools. To access them you need to be a registered Apple developer. The suite of tools is collectively called Xcode. Xcode includes a number of tools, each tackles a different part of the puzzle:

Signing up is done here: http://developer.apple.com/

  • Xcode. This is the central piece of the Xcode suite. It is where SDK projects are created, managed, edited and run. It’s a very powerful IDE that has many features to help you put together the application including code completion, refactoring and links to relevant documentation.
  • Interface Builder. Is a powerful graphical editor in which you interactively create the user interface for your SDK iPhone application.
  • iPhone Simulator. This is used by Xcode and Dashcode to run applications on the Mac desktop for testing purposes. It presents a running iPhone in a desktop window. A very convenient and time saving tool.
  • Instruments is a program that helps you to debug, profile, and trace your program. This is how SDK programs are debugged and finely tuned for performance.
  • Dashcode. Not really part of the Xcode suite but it’s bundled with it. Dashcode is a development environment that was first created for developing dashboard widgets (which are actually little web applications). In its current incarnation, it can build widgets as well as iPhone web sites. Dashcode outputs web pages, so you will be making use of your HTML, JavaScript CSS knowledge.

The Dashcode Route

Dashcode is a strange beast. It’s part of the Xcode suite, but does not really interact with the other components (except for the iPhone simulator it uses to run projects you develop with it).

Dashcode is an IDE geared to building iPhone web apps. It has a number of templates you can use as a starting point for your app (Navigation based application, Tab bar based application etc) and take it from there.

There is a control library that you can use, dragging out controls onto your interface and then assigning properties and logic.

Dashcode saves its projects as a Dashcode project file, and when you are done you export the project as an html/javascript/css site for deployment.

It isn’t built for very elaborate complicated apps that have a lot of backend code, but if you have a straightforward self contained idea. There is nothing faster than Dashcode for putting it together.

The user guide to Dashcode can be found here


The Dashcode IDE, providing a library of controls a layout area and code editing section

 


Previewing a site developed in Dashcode on the iPhone simulator

 

Using all that webkit can offer along with one of the frameworks, or building your site using DashCode allows you to create something very close to a native iPhone app that is sensitive to orientation changes, uses animation for transitions and displays the iPhone UI widgets. What you will be missing is this:

  • No access to features like camera, recording or location services
  •  Cannot get rid of the browser toolbar on the bottom
  •  Your site is shown in a browser and not as a separate app
  •  And the biggest drawback: it cannot be sold at the app store, so if you are planning on making money off your content it will need to be handled by you, rather than using the app store model and getting the exposure.

Using the SDK

To gain the full leverage of the app store and to take full advantage of all the iPhone has to offer, you need to use the iPhone SDK.

Creating an iPhone SDK app exposes the full potential of the iPhone. The SDK provides an incredibly rich collection of frameworks each responsible for a particular area of functionality.

The big picture is like this: You create an application in Xcode, build the user interface in Interface Builder and run it in the iPhone Simulator.

The main framework that you most likely will become most familiar with is Cocoa Touch. Among other things it contains the UIKit framework and the address book UI framework. It also supports windowing, events and user-interface management plus much more.

There is a lot of heavy lifting to be done here and a lot of information to be absorbed in order to take advantage of the richness the iPhone provides.

Fortunately there is tons of information, documentation, sample code and introduction videos available here: http://developer.apple.com/iphone/

The main concepts that you need to wrap your head around are:

  • The basic flow Xcode uses for producing an app
  • The frameworks available, what is responsible for which type of functionality
  •  Objective-c. The language used to program in Xcode


Xcode provides many project templates that you can use as a starting point for the major categories of applications: Navigation based application, Tab Bar Application etc.

The first step to starting with SDK development is to download the SDK and install it. The SDK is a hefty 1GB download and requires registration as an Apple developer.

The second step is to figure out what’s going on and get your bearings within this environment. The introductory videos are a good place to start and get oriented.

You can find them here: 
http://developer.apple.com/iphone/index.action

Xcode. The nerve center of the IDE development flow



Interface Builder. The tool you use to visually lay out the iPhone app interface

SDK Hybrids

This last type is basically an SDK app with a twist. Sections of the app are actually Safari browser panes that are showing web pages.

This splits the development into the section that will be written using Xcode and objective c and the section that will be fetching information from the web and and presenting it in a browser view.

Basically Xcode will be used to create the application running on the iPhone and Dashcode will be used to build the web sections of the app. Your application is the combination of these two technologies cooperating.

A good reference for this type of app can be found in the user interface guidelines

Summary

To sum all this up, let’s look at the most important elements needed to create content for the iPhone:

  • Immersion: Get an iPhone or iPod Touch and experience the user interface. Getting to know it is the only way of creating content that fits.
  • Planning: Nothing much to add here. Make sure your content has a purpose and you know what it is.
  • Do Nothing: Chances are your site works on the iPhone as is. You might not have to do much.
  • Do a little: You can take just a few steps to make your site play nice on the iPhone. A few changes can make a huge difference and make your site feel at home.
  • Develop an iPhone site: Create a site that is optimized for the iPhone, making it look like a native iPhone app as much as possible.
  • Create a site with Dashcode: Create sites specifically for the iPhone using the convenient and powerful Dashcode IDE.
  • Full blown SDK application:Use the Xcode suite to build native iPhone applications that can be submitted and sold on the Apple App Store.
  • An SDK Hybrid application: An iPhone application can be built as a combination of a native app and a web app, where the SDK app hosts web views presenting data from the web. This allow you to use your abilities from both environments.

Resources

Written exclusively for WDD by Etan Rozin. He’s a user interface designer and runs his own website at: www.rozin.com

The Original paper come from: http://www.webdesignerdepot.com/2009/11/the-ultimate-toolbox-for-iphone-development/

 

 

iPhone development can be intimidating, especially to someone who’s unfamiliar with Macs, or the way iPhone apps work.

But with currently more than 100,000 apps officially available from the App Store, it’s kind of hard for a developer to ignore the potential market the iPhone provides.

And there are apps for virtually anything you could think of, from games to productivity apps to horoscopes to news and more.

Below are 70 tools, tutorials, and resources to help you get started developing your own iPhone apps. There’s everything from basic tutorials to templates to resource libraries to help you on your way.

 

Tutorials

How to Get Started with iPhone Dev A very thorough article on how to start developing your own iPhone apps.

Learn How to Develop for the iPhone
An excellent tutorial from Tuts+ that covers the development of websites specifically for the iPhone or iPod Touch.

First iPhone Application
This post from iPhone SDK offers an extensive overview of how to develop your first basic iPhone application.

How I Wrote an iPhone Application
This article gives a first-hand account of building an iPhone app, including the thought process behind development and some code snippets.

Cocoa Touch Tutorial: iPhone Application Example
This tutorial covers how to develop Cocoa iPhone apps using Interface Builder to quickly build your first application.

Sliding UITextFields Around to Avoid the Keyboard
This tutorial covers the basics of moving text fields around on an iPhone app so that they don’t interfere with the on-screen keyboard.

Develop iPhone Web Applications with Eclipse
A very comprehensive article from IBM on using Eclipse to develop your iPhone apps.

iPhone Development with PHP and XML
Another article from IBM on developing apps, this time with PHP and XML.

Developing iPhone Applications Using Ruby on Rails and Eclipse
The first in a series of articles from IBM on using Ruby on Rails and Eclipse to develop iPhone apps.

Your First iPhone Application
A tutorial for creating your first app, from the official Apple iPhone OS Reference Library.

How to Make an iPhone Application on XCode
A simple video tutorial that shows you how to build an iPhone app on XCode.

iPhone SDK Development Tutorial – First Step Towards the App Store
Another great video tutorial that shows the first steps in building apps for the app store using XCode.

Make an iPhone App Using the Envato API
A great tutorial from Tuts+ that shows you how to use the Envato Marketplace API to develop your own iPhone apps.

Building PhotoKast: Creating an iPhone App in One Month
This photo tutorial shows you the complete process of building an iPhone app, with illustrations.

Perfect Multi-Column CSS Liquid Layouts: iPhone Compatible
This tutorial shows you how to build liquid CSS layouts that are iPhone compatible.

iPhone Dev Sessions: How to Make an Orientation-Aware Clock
This tutorial covers how to build an orientation-aware clock, which provides great insight into building any app that is orientation-aware.

iPhone SDK: Interface Builder Tutorial
A very short, simple intro to how the Interface Builder works.

Parsing XML Files
This tutorial from iPhone SDK offers all the information you need for parsing XML files within applications on the iPhone.

iPhone Gaming Framework: Stage 1 Tutorial
This tutorial shows you how to get your basic screen management system running so you can start developing iPhone games.

iPhone Game Programming Tutorial: Part 1
Here’s a complete tutorial for creating a Pong-like iPhone game.

So You’re Going to Write an iPhone App…
This tutorial gives a great overview of the app development process and some things to consider while developing.

Advanced iPhone Development
This article looks at some more advanced aspects of iPhone application development.

Building an iPhone App in a Day
A brief look at what it takes to build an iPhone app really quickly.

Build an iPhone Webapp in Minutes with Ruby, Sinatra and iUI
An overview of fast development techniques for iPhone webapps.

Finding iPhone Memory Leaks: A “Leaks” Tool Tutorial
Learn how to find memory leaks in your iPhone apps using the “Leaks” tool.

iPhone Application Development, Step by Step
A great, step-by-step look at the app development process.

iPhone App Development: Where to Start
A great article that talks about iPhone app development from the perspective of someone who’s never done any Apple or Mac development (or even used a Mac) previously.

Parsing XML on the iPhone
Another great look at how to parse XML within iPhone apps.

iPhone Development Central
This site offers a huge variety of video tutorials for iPhone developers, broken down for beginner, intermediate and advanced developers.

iPhone SDK Tutorial: Reading Data from a SQLite Database
A simple tutorial for using SQLite with the iPhone SDK.

iPhone Dev Sessions: Create a Navigation-Based Application
This comprehensive tutorial shows you how to create a navigation-based application from XCode.

iPhone SDK Tutorial: Build a Simple RSS Reader for the iPhone
This tutorial shows you how to build a simple RSS feed reader from the ground up.

Multi Touch Tutorial
This tutorial gives a great introduction to the iPhone’s multi touch interface.

Howto: iPhone Application Development Environment
This tutorial shows how one developer set up their app development environment, with tips for setting up your own.

iPhone Application Programming
Downloadable lectures from Stanford’s iPhone Application Programming class.

Introduction to iPhone Application Development
Downloadable course materials from a one-week MIT course on iPhone app development.

iPhone Programming Tutorial – Using openURL to Send Email from Your App
This tutorial shows you how to use openURL to allow your apps to send email.

How to Create Your first iPhone Appllication
Another comprehensive tutorial for creating your first iPhone app from the ground up.

 

Tools

PhoneGap
PhoneGap speeds up app development for developers who already know HTML and JavaScript but also want to take advantage of the core features of the iPhone SDK.

Morfik
Morfik is a downloadable tool that speeds up development of rich internet apps.

iPhone GUI PSD 3.0
A set of downloadable Photoshop files with iPhone GUI images.

iPhone PSD Vector Kit
A PSD set that comes with several button elements as well as six different iPhone interface options.

iPhone Wire Frames
iPhone Wire Frame stencil files for use with OmniGraffle.

Yahoo! Design Stencil Kit
A downloadable package of UI stencils from Yahoo! that includes iPhone images.

iPhone UI Vector Elements
Downloadable vector images of different iPhone elements.

Three20
A library of open source iPhone app elements and frameworks.

gdata-objectivec-client
The Google Data API’s Objective-C client library.

Are You iPhoned?
A simple site that checks to see if you’re visiting from an iPhone and gives you the code to do the same on your own sites.

31 iPhone Applications with Source Code
A library of more than thirty iPhone apps with their source code available.

iPhone Samples
Sample UI elements for the iPhone.

iUI: iPhone User Interface Framework
A free UI framework for Safari development on the iPhone.

35 Free Icon Sets for your iPhone
35 icon sets you can download and use in your iPhone development.

TestiPhone.com – iPhone Simulator
An iPhone simulator for testing your iPhone web apps.

iPhoney
Another simulator for testing your iPhone web apps.

 

Resources and Articles

iPhone Dev Connection
Apple’s official iPhone development site.

The Darker Side of iPhone App Development
An article that covers some of the restrictions and limitations imposed by Apple for iPhone apps.

Avoiding iPhone App Rejection From Apple
A great article that tells you how to not get rejected by the App Store.

14 Essential XCode Tips, Tricks and Resources for iPhone Devs
A roundup of some great developer resources.

iPhoneDevForums
An iPhone/iPod touch development discussion forum aimed to assist fellow developers as they code in Apple’s SDK. There is also a job board where developers and entrepreneurs can share and discover one another’s services to start projects of their own.

iCodeBlog
The iCodeBlog has tons of great articles, news, and tutorials related to iPhone development.

iPhoneWebDev
An iPhone developer resource center and community.

iPhone Toolbox
A blog that covers news, apps, and more related to the iPhone.

iPhone Open Application Development
O’Reilly Media’s iPhone application development book.

iPhone Web Application Submission
The official place to submit your iPhone web applications.

iPhone Application and Website Development: All Tools and Tutorials You Need
A huge roundup of resources for developing both iPhone apps and optimized websites.

iPhone Dev SDK Forum
A great forum for getting answers to your iPhone SDK development questions.

iPhone Application Developer Interview
An interview with iPhone app developer Darren Andes, the developer of the Baby Tracker: Nursing app.

Seven Things all iPhone Apps Need
An overview of some must-have features for iPhone apps.

5 Free Resources for iPhone App Development
A roundup of some handy, free resources for developing your iPhone apps.

Top 10 Tutorials to Develop iPhone Apps
A ranked listing of great iPhone development tutorials.

100 Free Courses and Tutorials for Aspiring iPhone App Developers
A huge list of iPhone development courses, many from traditional universities.

29 iPhone App & Website Development Resources and Tutorials Places
Another excellent roundup of iPhone development resources.

 

 

Drawing a Grid in a UITableView

2009年12月22日 22:20

The Original paper come from: http://dewpoint.snagdata.com/2008/10/31/drawing-a-grid-in-a-uitableview/

 UITableView is probably the most used view on the iPhone. It’s flexible and the UI is ideally suited to use on the iPhone. There are lots of examples on how to add multiple items to a UITableViewCell. However, I needed to present some data in a more traditional spreadsheet style grid. The results worked well and enabled me to pack a lot of information on the screen that was very hard to follow without the vertical grid. I’ll show a very simplified version here you can use to add vertical lines to your UITableView.

 First we need to create a subclass of UITableViewCell. This is so we can override drawrect and draw our lines and to add an array to hold a list of positions where we’ll draw the lines.

@interface MyTableCell : UITableViewCell {
	NSMutableArray *columns;
}
- (void)addColumn:(CGFloat)position;
@end

 In this simplified example we’ll leave the positioning of the actual text in the cells in the UITableViewController and place it manually (full source code is attached at the end). We’re just providing a mechanism for drawing vertical lines to make a grid. Column locations are added by calling addColumn:

- (void)addColumn:(CGFloat)position {
	[columns addObject:[NSNumber numberWithFloat:position]];
}

 Now lets override drawRect. In it we grab the current graphics context and set the line color and width. Then we iterate over our columns array drawing a line from the top of the cell row to the bottom at each position stored in the array.

- (void)drawRect:(CGRect)rect {
	CGContextRef ctx = UIGraphicsGetCurrentContext();
	// Use the same color and width as the default cell separator for now
	CGContextSetRGBStrokeColor(ctx, 0.5, 0.5, 0.5, 1.0);
	CGContextSetLineWidth(ctx, 0.25);
 
	for (int i = 0; i < [columns count]; i++) {
		CGFloat f = [((NSNumber*) [columns objectAtIndex:i]) floatValue];
		CGContextMoveToPoint(ctx, f, 0);
		CGContextAddLineToPoint(ctx, f, self.bounds.size.height);
	}
 
	CGContextStrokePath(ctx);
 
	[super drawRect:rect];
}

 To add columns to the view just call

[cell addColumn:50];

 when you’re building each cell.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
	NSString *MyIdentifier = [NSString stringWithFormat:@"MyIdentifier %i", indexPath.row];
 
	MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
 
	if (cell == nil) {
		cell = [[[MyTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
 
		UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0, 30.0,tableView.rowHeight)] autorelease];
		[cell addColumn:50];
		label.tag = LABEL_TAG;
		label.font = [UIFont systemFontOfSize:12.0];
		label.text = [NSString stringWithFormat:@"%d", indexPath.row];
		label.textAlignment = UITextAlignmentRight;
		label.textColor = [UIColor blueColor];
		label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
		UIViewAutoresizingFlexibleHeight;
		[cell.contentView addSubview:label]; 
 
		label =  [[[UILabel alloc] initWithFrame:CGRectMake(60.0, 0, 30.0,tableView.rowHeight)] autorelease];
		[cell addColumn:120];
		label.tag = VALUE_TAG;
		label.font = [UIFont systemFontOfSize:12.0];
		// add some silly value
		label.text = [NSString stringWithFormat:@"%d", indexPath.row * 4];
		label.textAlignment = UITextAlignmentRight;
		label.textColor = [UIColor blueColor];
		label.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
		UIViewAutoresizingFlexibleHeight;
		[cell.contentView addSubview:label];
	}
 
	return cell;
}

 That’s it. Being a bit dense I beat my head on my desk a few days before it become obvious how blindingly simple it really was. A lot was just learning ObjectiveC and how UIKit works in general. I’m now working on a GridTableView library that will add a good bit of functionality and ease of use. I’ll post it here.

 

 怎么在iPhone程序中读取PDF的内容呢?答案是,苹果为我们准备了一个很神奇的framework Q2D(Quartz 2D)。Q2D提供了全套的PDF读取API,接下来我们来看看如果简单的使用Q2D来读取PDF文件:

 我建立了一个工程叫iPhonePDF, 添加了一个UIScrollView(不知道怎么添加UIScrollView? 添加一个UIView然后把interface上的UIView改成UIScrollView就可以啦…)名为PDFView

看看PDFView里面有什么吧

@interface PDFView : UIScrollView {
 NSString *filePath;
 CGPDFDocumentRef pdfDocument;
 CGPDFPageRef page;
 int pageNumber;
}
 
@property (copy, nonatomic) NSString *filePath;
@property int pageNumber;
 
-(CGPDFDocumentRef)MyGetPDFDocumentRef;
-(void)reloadView;
-(IBAction)goUpPage:(id)sender;
-(IBAction)goDownPage:(id)sender;
@end

filePath是储存pdf文件的位置的,得到文件位置就是老话题了:[NSBundle mainBundle]… 后面的会写吧… 不记得了在我博客里面搜索吧

CGPDFDocumentRef是PDF文档索引文件,Q2D是Core Foundation的API,所以没看到那个星星~

CGPDFPageRef是PDF页面索引文件

pageNumber是页码

下面的几个函数其实一看就明了了,翻页的,和刷新页面的。第一个是自定义的getter

然后我们看看m文件里面有用的方法:

@implementation PDFView
@synthesize filePath,pageNumber;
 
- (void)drawRect:(CGRect)rect //只要是UIView都有的绘图函数,基础哟~
{
 if(filePath == nil) //如果没被初始化的话,就初始化
 {
  pageNumber = 10;   //这个其实应该由外部函数控制,不过谁让这个程序特别简单呢
  filePath = [[NSBundle mainBundle] pathForResource:@"zhaomu" ofType:@"pdf"];
                //这里,文件在这里!
  pdfDocument = [self MyGetPDFDocumentRef]; //从自定义getter得到文件索引
 }
 
 CGContextRef myContext = UIGraphicsGetCurrentContext();
        //这个我研究了一段时间呢,不过就照打就可以了
 
 page = CGPDFDocumentGetPage(pdfDocument, pageNumber);
        //便捷函数,告诉人家文档,告诉人家页码,就给你页面索引
 
 CGContextDrawPDFPage(myContext, page);
        //画!
}
 
//此getter可以考虑照打... 都是CF函数,我看到就恶心。
//其实不是很难了,得到文件,转换成URL,然后通过
//CGPDFDocumentCreateWithURL(url)得到文件内容索引
//Ta Daaa~~
- (CGPDFDocumentRef)MyGetPDFDocumentRef
{
 CFStringRef path;
 CFURLRef url;
 CGPDFDocumentRef document;
 path = CFStringCreateWithCString(NULL, [filePath UTF8String], kCFStringEncodingUTF8);
 url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
 CFRelease(path);
 document = CGPDFDocumentCreateWithURL(url);
 CFRelease(url);
 return document;
}
 
-(void)reloadView
{
 [self setNeedsDisplay]; //每次需要重画视图了,就call这个
}
 
-(IBAction)goUpPage:(id)sender
{
 pageNumber++;
 
 [self reloadView];
}
-(IBAction)goDownPage:(id)sender
{
 pageNumber--;
 [self reloadView];
}
@end

 

CoreData实例分析学习(1)

2009年12月15日 23:00

 Core Data是个好东西,在数据储存操作上速度快,容易操作,是一种类似关系数据库的东西。但是有些不那么好学,那到底Core Data是怎么操作的呢?怎么用呢?怎么来编程呢?我们一起来学习吧,接下来使用苹果提供的实例程序Locations来作分析:

 

>程序介绍:

右侧是改程序的截图,基本上来说就是通过使用Core Location来得到当时的位置,然后在点击“+”的时候记录下当时的经纬度。通过UITableViewController的功能来添加,编辑,删除等功能。整体程序使用Core Data来储存数据,实体(Entity)为一个位置,包括以下参数:1,时间(收集数据的时间)2,纬度,3,经度

首先我们看看该程序的AppDelegate.h

  1. @interface LocationsAppDelegate : NSObject  {
  2.     UIWindow *window;
  3.     UINavigationController *navigationController; //导航栏
  4.  
  5.     //以下定义了Core Data的三个决定性组建,等后面m文件里面再多介绍
  6.     NSPersistentStoreCoordinator *persistentStoreCoordinator;
  7.     NSManagedObjectModel *managedObjectModel;
  8.     NSManagedObjectContext *managedObjectContext;
  9. }
  10.  
  11. @property (nonatomic, retain) IBOutlet UIWindow *window;
  12. @property (nonatomic, retain) UINavigationController *navigationController;
  13.  
  14. - (IBAction)saveAction:sender; //这个没找到作用...根本就没用到IB
  15.  
  16. //还记得吧,nonatomic是因为这个程序是单线程
  17. @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
  18. @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
  19. @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator
  20.                               *persistentStoreCoordinator;
  21. @property (nonatomic, readonly) NSString *applicationDocumentsDirectory;
  22. //程序文档目录是主要为了给NSPersistentStoreCoordinator找个存SQLite文件的地方
  23. @end

  

从上面的我们能看出来,该程序是通过一个根Core Data数据管理来管理整个程序的CoreData数据的,接下来看m文件也会对此作更多的理解。

 

  1. #import "LocationsAppDelegate.h"
  2. #import "RootViewController.h" //该程序使用了一个根视图控制器,所以导入了这个类
  3. @implementation LocationsAppDelegate
  4. @synthesize window;
  5. @synthesize navigationController;
  6.  
  7. - (void)applicationDidFinishLaunching:(UIApplication *)application {
  8.         //初始化根视图控制器,它是一个列表视图控制器
  9.         RootViewController *rootViewController = [[RootViewController alloc]
  10.              initWithStyle:UITableViewStylePlain];
  11.  
  12.         //通过下面的自定义getter得到CoreData的“被管理对象内容器”
  13.         NSManagedObjectContext *context = [self managedObjectContext];
  14.         if (!context) {
  15.                 // 如果getter出错,在这里来排错
  16.         }
  17.         rootViewController.managedObjectContext = context;
  18.         //rootViewController有一个本地“被管理对象内容器”,在这里赋值过去
  19.  
  20.         UINavigationController *aNavigationController = [[UINavigationController alloc]
  21.              initWithRootViewController:rootViewController];
  22.         self.navigationController = aNavigationController;
  23.         //初始化导航栏,根视图为rootViewController,并指定该导航栏为程序导航栏
  24.         [window addSubview:[navigationController view]];
  25.         [window makeKeyAndVisible];
  26.  
  27.         //由于导航栏retain了根视图,所以在这里可以release掉它了
  28.         [rootViewController release];
  29.         //由于self已经retain了导航栏,所以导航栏可以release
  30.         [aNavigationController release];
  31. }
  32.  
  33. //applicationWillTerminate: 在程序结束前,Core Data会保存任何对其的更改
  34. - (void)applicationWillTerminate:(UIApplication *)application {
  35.  
  36.     NSError *error;
  37.     if (managedObjectContext != nil) {
  38.         if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
  39.                         // Handle the error.
  40.         }
  41.     }
  42. }
  43.  
  44. //在得到点击事件后,保存更改
  45. - (IBAction)saveAction:(id)sender {
  46.  
  47.     NSError *error;
  48.     if (![[self managedObjectContext] save:&error]) {
  49.                 // Handle error
  50.     }
  51. }
  52.  
  53. //自定义的managedObjectContext的getter, 它其实是真正在使用的时候的被操作对象
  54. - (NSManagedObjectContext *) managedObjectContext {
  55.  
  56.     //如果已经有这个对象,就直接返回,否则继续
  57.     if (managedObjectContext != nil) {
  58.         return managedObjectContext;
  59.     }
  60.  
  61.     NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
  62.     if (coordinator != nil) {
  63.         managedObjectContext = [[NSManagedObjectContext alloc] init];
  64.         [managedObjectContext setPersistentStoreCoordinator: coordinator];
  65.        //这里可以看到,“内容管理器”和“数据一致性存储器”的关系,
  66.        //managedObjectContext需要得到这个“数据一致性存储器”
  67.     }
  68.     return managedObjectContext;
  69. }
  70.  
  71. //自定义的CoreData数据模板的getter,数据模板其实就是一个描述实体与实体的关系
  72. //,类似于关系型数据库的关系描述文件
  73. - (NSManagedObjectModel *)managedObjectModel {
  74.  
  75.     if (managedObjectModel != nil) {
  76.         return managedObjectModel;
  77.     }
  78.     managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
  79.     //从本地所有xcdatamodel文件得到这个CoreData数据模板
  80.     return managedObjectModel;
  81. }
  82.  
  83. //自定义“数据一致性存储器” persistentStoreCoordinator的getter
  84. - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
  85.  
  86.     if (persistentStoreCoordinator != nil) {
  87.         return persistentStoreCoordinator;
  88.     }
  89.  
  90.     //定义一个本地地址到NSURL,用来存储那个SQLite文件
  91.     NSURL *storeUrl = [NSURL fileURLWithPath:
  92.             [[self applicationDocumentsDirectory]
  93.                             stringByAppendingPathComponent: @"Locations.sqlite"]];
  94.  
  95.         NSError *error;
  96.     persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
  97.             initWithManagedObjectModel: [self managedObjectModel]];
  98.     //从这里可以看出,其实persistentStoreCoordinator需要的不过是一个
  99.     //存储数据的位置,它是负责管理CoreData如何储存数据的
  100.     if (![persistentStoreCoordinator
  101.         addPersistentStoreWithType:NSSQLiteStoreType
  102.         configuration:nil
  103.         URL:storeUrl
  104.         options:nil
  105.         error:&error]) {
  106.         // Handle the error.
  107.     }   
  108.  
  109.     return persistentStoreCoordinator;
  110. }
  111.  
  112. //返回该程序的档案目录,用来简单使用
  113. - (NSString *)applicationDocumentsDirectory {
  114.  
  115.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
  116.                             NSUserDomainMask, YES);
  117.     NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
  118.     return basePath;
  119.     //我原来的帖子中介绍过,方法其实是一模一样的
  120. }
  121.  
  122. - (void)dealloc {
  123.  
  124.     //释放内存
  125.     [managedObjectContext release];
  126.     [managedObjectModel release];
  127.     [persistentStoreCoordinator release];
  128.  
  129.         [navigationController release];
  130.         [window release];
  131.         [super dealloc];
  132. }
  133. @end

 

从上面的程序主代理文件可以看出,CoreData的简单使用不过是通过三个组建。

NSManagedObjectModel来描述实体与实体的关系,也就是类似于表和表的关系。
NSManagedObjectContext来得到被储存内容的文件管理器,对数据作直接操作
NSPersistentStoreCoordinator来管理数据的储存位置,储存方法(SQLite)

你对Core Data理解更多了么?

 

补一下“实体”的概念,实体也就是Entity,在打开xcdatamodel文件的时候,我们可以看到

屏幕快照 2009-08-26 下午05.08.29

在这里,这个实体叫“Event”,而实体的参数有“创建日期”,“纬度”,“经度”。也就是说,其实这个实体被使用后,我们可以这样理解,实体就是表名,而参数就是列名,然后整个实体就是一张表。当这个Model描述多个实体的关系的时候,就像是一个关系型数据库一样,虽然苹果说“不是!”