Fork me on GitHub

2012年3月1日

摘要: 双向关系双向的时候,只用指定一边,另外一边自动指定,比如,如果一个帐号只有一个联系人,而一个联系人对应一个帐号的话,那么帐号表和联系人表就是一一对应的关系,将他们指定为双向的,如下面将cnt1.act = act1; cnt2.act = cnt2;则act1.cnt和act2.cnt也是有值的。注释掉的两句可有可无。删除规则这里将Account表下面的cnt的删除规则设定为cascade,则在删除act1的时候,cnt1也被删除了。而Contact表没有将它下面的act的删除规则设置为cascade,在删除cnt1的时候,act1还存在。一对多的关系上面假设一个帐号只有一个联系人是不合理的, 阅读全文
posted @ 2012-03-01 19:50 pengyingh 阅读(3444) 评论(0) 推荐(0)
摘要: - (void)Connect{ [self ConnectToServerHost:HOST Port:PORT]; [self.is setDelegate:self]; [self.os setDelegate:self]; [self.is scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [self.os scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [self.is op... 阅读全文
posted @ 2012-03-01 19:42 pengyingh 阅读(174) 评论(0) 推荐(0)
摘要: //加载Bundle中的html文件。 NSString *Path = [[NSBundle mainBundle] pathForResource:@"chat.html" ofType:nil]; [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:Path]]]; // 执行其中的Javascript NSString *str = [NSString stringWithFormat:@"addmsg(\"%c%c%c\")", & 阅读全文
posted @ 2012-03-01 15:50 pengyingh 阅读(231) 评论(0) 推荐(0)
摘要: 在程序退到后台的时候马上弹出一个PUSH- (void)applicationDidEnterBackground:(UIApplication *)application {/*Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. If 阅读全文
posted @ 2012-03-01 15:47 pengyingh 阅读(637) 评论(0) 推荐(0)
摘要: 目的:重用代码,将公用的东西写到一个静态库中,公用。新建一个Cocoa Touch静态库项目MyLib,编写相应代码。新建一个测试项目TestLib,打开MyLib,选中MyLib中的MyLib,拖入TestLib项目中,选中Copy。准备库头文件,加入到TestLib中。双击TestLib中Targets下的TestLib目标,在General中的Direct Dependencies中加入MyLib。点击TestLib中Targets下的TestLib目标左边的小三角,展开TestLib中的MyLib,将其中的libMyLib.a拖入Link Binary With Library中。编写 阅读全文
posted @ 2012-03-01 15:42 pengyingh 阅读(237) 评论(0) 推荐(0)
摘要: 开发项目的时候不用管显示语言的问题,在代码中任何地方要显示文字都这样调用:NSLocalizedString(@"aaa", @"bbb");这里aaa相当于关键字,它用于以后从文件中取出相应语言对应该的文字。bbb相当于注释,翻译人员可以根据bbb的内容来翻译aaa,这里的aaa与显示的内容可以一点关系也没有,只要程序员自己能看懂就行。比如,一个页面用于显示联系人列表,这里调用可以这样写。NSLocalizedString(@"shit_or_anything_you_want", @"联系人列表标题");项目写 阅读全文
posted @ 2012-03-01 15:35 pengyingh 阅读(274) 评论(0) 推荐(0)
摘要: Ad Hoc iTunesAd Hoc iTunes 512*512 iTunesArtworkApp Store:iPhone/iPod touch 57*57 Icon.pngiPhone 4iPad 72*72 Icon-72.pngHome screen:iPhone/iPod touch 57*57 Icon.pngiPhone 4 114*114 Icon@2x.pngiPad 72*72 Icon-72.pngSettings:iPhone 29*29 Icon-Small.pngiPhone 4 58*58 Icon-Small@2x.pngiPad 29*29 Icon-Sm 阅读全文
posted @ 2012-03-01 15:25 pengyingh 阅读(196) 评论(0) 推荐(0)
摘要: 1 @implementation UIImage (grayscale)2 3 typedef enum {4 5 ALPHA = 0,6 7 BLUE = 1,8 9 GREEN = 2,10 11 RED = 312 13 } PIXELS;14 15 - (UIImage *)convertToGrayscale {16 17 CGSize size = [self size];18 19 int width = size.width;20 21 int height = size.height;22 23 24 // the pixels will be painted to thi 阅读全文
posted @ 2012-03-01 15:22 pengyingh 阅读(498) 评论(0) 推荐(0)
摘要: 添加一个UITapGestureRecognizer;然后:tgr= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(MapTouched:)]; [MapView addGestureRecognizer:tgr];其中响应函数如下:- (void)MapTouched:(UITapGestureRecognizer*)t{ CGPointpt = [tlocationInView:MapView]; NSLog(@"%@",NSStringFromCGPoint(pt));} 阅读全文
posted @ 2012-03-01 15:18 pengyingh 阅读(319) 评论(0) 推荐(0)
摘要: NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];// NSString *tzStr = [[date description] substringFromIndex:20];// NSLog(@"\ndate\t:[%@]\ntime zone\t:[%@]", [date description], tzStr);// [dateFormatter setTimeZone:tzStr];[dateFormatter setDateFormat:@"MM d','h:m 阅读全文
posted @ 2012-03-01 15:14 pengyingh 阅读(917) 评论(0) 推荐(0)
摘要: - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight这个函数是UIImage的一个实例函数,它的功能是创建一个内容可拉伸,而边角不拉伸的图片,需要两个参数,第一个是不拉伸区域和左边框的宽度,第二个参数是不拉伸区域和上边框的宽度。第一次用这个函数的时候一直搞不懂为什么只要两个参数就行,至少应该指定左上角和右下角,总共四个参数啊。后来读读文档才明白,只需要两个参数就行了。参数的意义是,如果参数指定10,5。那么,图片左边10个像素,上边5个 阅读全文
posted @ 2012-03-01 13:22 pengyingh 阅读(276) 评论(0) 推荐(0)
摘要: nonatomic:非原子性访问,不加同步,多线程并发访问会提高性能。如果不加此属性,则默认是两个访问方法都为原子型事务访问。 (atomic是Objc使用的一种线程保护技术,基本上来讲,是防止在写未完成的时候被另外一个线程读取,造成数据错误。而这种机制是耗费系统资源的,所 以在iPhone这种小型设备上,如果没有使用多线程间的通讯编程,那么nonatomic是一个非常好的选择。)assign:简单赋值,不更改索引计数对基础数据类型 (NSInteger)和C数据类型(int,float,double,char, 等)copy:建立一个索引计数为1的对象,然后释放旧对象 对NSStringre 阅读全文
posted @ 2012-03-01 10:05 pengyingh 阅读(4740) 评论(0) 推荐(0)
摘要: NSPredicate *p = [NSPredicate predicateWithFormat:@"SELF like[c] %@", @"aa*bb"];其中:SELF大小写都行。aa*bb使用了通配符,*号只能写在变量中,而不能这样@"SELF like[c] %@*%@", @"aa", @"bb"。字符串本来是要用引号括起来的,不过这里不用加,NSPredicate会自动加。测试布尔值 NSPredicate *p = [NSPredicate predicateWithFormat 阅读全文
posted @ 2012-03-01 09:55 pengyingh 阅读(207) 评论(0) 推荐(0)
摘要: 原始帖子只需要加入到pch文件中即可,__OPTIMIZE__这个编译选项是发布版本才有的,所以在编译调试版本的时候可以看到Log,而发布版本则没有Log。#ifndef __OPTIMIZE__#define NSLog(...) NSLog(__VA_ARGS__)#else#define NSLog(...) {}#endif 阅读全文
posted @ 2012-03-01 09:48 pengyingh 阅读(201) 评论(0) 推荐(0)
摘要: TableView.backgroundView=nil;TableView.backgroundColor=[UIColorclearColor];TableView.opaque=NO; 阅读全文
posted @ 2012-03-01 09:46 pengyingh 阅读(732) 评论(0) 推荐(0)
摘要: 只能输入非零开头的正整数用下面的代码- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ NSString *result = [textField.text stringByReplacingCharactersInRange:range withString:string]; if ([result length] == 0) return YES; // Allow delete ... 阅读全文
posted @ 2012-03-01 09:45 pengyingh 阅读(277) 评论(0) 推荐(0)
摘要: 使用NSFetchedResultsController和UITableView显示CoreData的数据时,如果用relationship作为分组的关键字。比如Contact和Group两个实例如下图:在显示的时候,创建NSFetchedResultsController/* Set up the fetched results controller. */ // Create the fetch request for the entity. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]... 阅读全文
posted @ 2012-03-01 09:16 pengyingh 阅读(3230) 评论(0) 推荐(0)
摘要: 1首先定义一个自定义类,如下@interfaceBookItem : NSObject{NSInteger booKDataID;NSString* bookName;NSString* bookDescription;NSString* bookFileName;NSInteger bookFileSize;NSString* recommendindex;NSDate* modifyTime;}@propertyNSInteger booKDataID;@property(nonatomic,retain) NSString* bookName;@property(nonatomic,re 阅读全文
posted @ 2012-03-01 08:29 pengyingh 阅读(5452) 评论(0) 推荐(0)
摘要: //// codeObj.h// encodeObject//// Created by 110 on 10-2-6.// Copyright 2010 __MyCompanyName__. All rights reserved.//#import <Cocoa/Cocoa.h>@interface codeObj : NSObject <NSCoding>{NSString *name;int magicNumber;float shoseSize;NSMutableArray *subThingies;}@property (copy) NSString *nam 阅读全文
posted @ 2012-03-01 07:06 pengyingh 阅读(758) 评论(0) 推荐(0)

导航