1.图片异步加载
//获取图片链接
- (void)loadImageFromURL:(NSURL*)url {
if (connection!=nil) { [connectionrelease]; } //in case we are downloading a 2nd image
if (data!=nil) { [datarelease]; }
NSURLRequest* request = [NSURLRequestrequestWithURL:urlcachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:60.0];
connection = [[NSURLConnectionalloc]initWithRequest:requestdelegate:self];//notice how delegate set to self object
//TODO error handling, what if connection is nil?
progress = [[UIActivityIndicatorViewalloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
progress.center =self.center;
[progressstartAnimating];
[selfaddSubview:progress];
}
//the URL connection calls this repeatedly as data arrives
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data==nil) {data = [[NSMutableDataalloc]initWithCapacity:2048]; }
[data appendData:incrementalData];
}
//the URL connection calls this once all the data has downloaded
- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
//so self data now has the complete image
[connection release];
connection=nil;
if ([[selfsubviews]count]>0) {
//then this must be another image, the old one is still in subviews
[[[selfsubviews]objectAtIndex:0]removeFromSuperview];//so remove it (releases it also)
}
//make an image view for the image
UIImageView* imageView = [[[UIImageViewalloc]initWithImage:[UIImageimageWithData:data]]autorelease];
//make sizing choices based on your needs, experiment with these. maybe not all the calls below are needed.
imageView.contentMode =UIViewContentModeScaleAspectFit;
imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight );
[self addSubview:imageView];
imageView.frame = self.bounds;
[imageView setNeedsLayout];
[selfsetNeedsLayout];
[datarelease];//don't need this any more, its in the UIImageView now
data=nil;
[progressremoveFromSuperview];
}
2登陆界面加post用户名给服务器http://download.csdn.net/download/lmmilove/4361660
3UITableView简单的设置界面
http://download.csdn.net/download/lmmilove/4366161
4程序内置购买,下载资源存储路径
NSString *paths = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *documentsDirectory = [paths stringByAppendingString:@"/Caches/"];
NSLog(@"%@",documentsDirectory);
NSString *path = [documentsDirectorystringByAppendingPathComponent:[NSStringstringWithFormat: @"Caches下的路径"]];