原来的网址:http://www.buildapp.net/iphone/show.asp?id=10273
2. 加边框
myWebView.layer.borderWidth = 5;
myWebView.layer.borderColor = [[UIColorcolorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor];
3. 清空View
for (UIView *subView in [controller.viewsubViews]){
[subViewremoveFromSuperview];
}
4. 添加navigationBar
[self.navigationController.view addSubview:self.navigationController.navigationBar];
5. 保存内存地址
[arrFriendretain];
6. 地图改变位置
- (void)gotoLocation:(CLLocationCoordinate2D)clloc
{
MKCoordinateRegionnewRegion;
newRegion.center= clloc;
newRegion.span.latitudeDelta= 0.01;
newRegion.span.longitudeDelta= 0.01;
[_googleView.mapsetRegion:newRegion animated:YES];
}
7. 进制转化
-(CFStringRef)EncodeUTF8Str:(NSString*)encodeStr{
CFStringRefnonAlphaNumValidChars = CFSTR("![ DISCUZ_CODE_1 ]’()*+,-./:;[email protected]_~");
CFStringRefpreprocessedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)encodeStr, CFSTR(""), kCFStringEncodingUTF8);
CFStringRefnewStr =CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,preprocessedString,NULL,nonAlphaNumValidChars,kCFStringEncodingUTF8);
returnnewStr;
}
//转换成GB2312
-(NSString*)EncodeGB2312Str:(NSString*)encodeStr{
CFStringRefnonAlphaNumValidChars = CFSTR("![ DISCUZ_CODE_1 ]’()*+,-./:;[email protected]_~");
NSString*preprocessedString = (NSString*)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)encodeStr, CFSTR(""), kCFStringEncodingGB_18030_2000);
NSString*newStr = [(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)preprocessedString,NULL,nonAlphaNumValidChars,kCFStringEncodingGB_18030_2000) autorelease];
[preprocessedStringrelease];
returnnewStr;
}
8. 时间格式转换
NSString*strTime=[NSStringstringWithFormat:@"%@",message.time];
NSDateFormatter*inform = [[NSDateFormatteralloc] init];
[inform setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate*parsed = [inform dateFromString: strTime];
[inform release];
NSDateFormatter*toform = [[NSDateFormatteralloc] init];
[toform setDateFormat:@"MM-dd HH:mm"];
cell.lblTime.text=[toform stringFromDate:parsed];
[parsed release];
[toform release];
//时间格式转换
NSString*strTime=[NSStringstringWithFormat:@"%@",message.time];
if([strTime length]>16) {
strTime=[strTime substringWithRange:NSMakeRange(5, 11)];
}
9. 类
[[Fraction class] t];
或者
Class clazz=[Fraction class];
[clazz t];
10. 内存
NSLog(@"arrFriend count=%d",[arrFriendretainCount]);
地图
控制地图的中心和显示大小
MKCoordinateRegionnewRegion;
newRegion.center= clloc;
newRegion.span.latitudeDelta=0.9;//0.01
newRegion.span.longitudeDelta= 0.9;
[_googleView.mapsetRegion:newRegion animated:YES];
[self.viewinsertSubview:mapView atIndex:0];
11. 动画
[UIViewbeginAnimations:@"hideView"context:nil];//开始动画 动画名称
[UIViewsetAnimationDuration:0.2];//动画速度
[UIViewsetAnimationCurve:UIViewAnimationCurveLinear];//动画方向
scrollVGlide.frame=CGRectMake(0, 0, 320, 200);
scrollVGlide.contentOffset=CGPointMake(0, 45);
[UIViewcommitAnimations];//结束动画
12. view 里的视图
for(UIView*v in[self.viewsubviews]) {
if([v isKindOfClass:[UIButtonclass]]==NO) {
[v removeFromSuperview];
}
}
13. 读取本地文件 内容
NSString*filePath=[[NSBundlemainBundle] pathForResource:@"1"ofType:@"txt"];
NSString*str=[[NSStringalloc] initWithContentsOfFile:filePath];
NSLog(@"%@",str);
14. 提取字符串
// 得到引用的用户名 和发表时间
-(NSString*)WebQuoteUserTime:(NSString*)strText
{
NSString*strResult=[[[NSStringalloc] init]autorelease];
NSString*strMiddle=strText;
NSRangerangQuote1=[strMiddle rangeOfString:@"[quote]"];
NSRangerangQuote=[strMiddle rangeOfString:@""];
NSRangerangSize=[strMiddle rangeOfString:@""];
if(rangQuote1.length>0&&rangQuote.length>0&&rangSize.length>0) {
strResult=[strMiddlesubstringWithRange:NSMakeRange(rangQuote.location+rangQuote.length,rangSize.location-rangQuote.location-rangQuote.length)];
}
returnstrResult;
}
15. xml序列化和反序列化
xml转换成对象称为反序列化
对象转换成xml 称为序列化
16. mac翻..阿..城墙
vbn系统自带的
17. NSString 初始化
Nsstring *str=nil;//如果不初始化访问的地址会有错不确定
18. 属性定义
@property(nonatomic,assign)NSInteger nodeCount;
@property(nonatomic,assign) NSInteger unreadMsgSum;
@property(nonatomic,retain)CatalogIDListClass *catalogIDList;
@property(nonatomic,retain)MessageInfoListClass *messageInfoList;
@property(nonatomic,copy)NSString *parentcatalogID;
@property(nonatomic,copy)NSString *Etag_Catalog;
19. 属性 也要再定义
也要释放如果用retain 当变量改变是也可以在改变
20. 每隔一段时间 执行 事件
[NSTimerscheduledTimerWithTimeInterval:0.5target:selfselector:@selector(makeMyProgressBarMoving)userInfo:nilrepeats:NO];
21. 页面推送方式
[selfpresentModalViewController:picker animated:YES];
22. 命令打开 svn
cddesktop/megafon
svnst .
svnupdate
Lastlogin: Fri Apr 29 10:02:58 on ttys001
Sunnys-iMac:~Sunny$ pwd
/Users/Sunny
Sunnys-iMac:~Sunny$ cd desktop
Sunnys-iMac:desktopSunny$ ls
02-代码Megafon iphone低保真设计.ppt
1.jpg OOo_3.2.0_MacOSXIntel_install_en-US.dmg
2.jpg QQ
MegaFon head.jpg
Sunnys-iMac:desktopSunny$ cd 02-代码
Sunnys-iMac:02-代码Sunny$ ls
MegaFon.xcodeproj ThirdParty build
Src UnitTest
Sunnys-iMac:02-代码Sunny$ svn st
? build
? Src/ViewControllers/Product.h
? Src/ViewControllers/Product.m
? Src/ViewControllers/head.jpg
M Src/ViewControllers/LoginViewController.m
M Src/ViewControllers/ContactsViewController.h
M Src/ViewControllers/ContactsViewController.m
? MegaFon.xcodeproj/Sunny.mode1v3
M MegaFon.xcodeproj/project.pbxproj
Sunnys-iMac:02-代码Sunny$ svn up
Atrevision 53.
Sunnys-iMac:02-代码Sunny$
Sunnys-iMac:02-代码Sunny$ svn update
Atrevision 53.
Sunnys-iMac:02-代码Sunny$
就可以了
23. UITableView
- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView
{
NSArray*arr1=[[NSArrayalloc]initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"#",nil];
NSMutableArray*keyArray = [[NSMutableArrayalloc] init];
[keyArray addObject:UITableViewIndexSearch];
//[keyArrayaddObjectsFromArray:arr1
// sortedArrayUsingSelector:@selector(compare:)]];
[keyArray addObjectsFromArray:arr1];
returnkeyArray;
returnarr1;
}
24. 只有在此时cai释放内存
alloc
retain
copy
25. 键盘样式
field.keyboardType= UIKeyboardTypeNumberPad;
26. 两个字符串忽略大小写相等
[self.strFatherVCcaseInsensitiveCompare:@"Prifile"]==NSOrderedSame
27. 键盘 return
fieldLastName.returnKeyType= UIReturnKeyDone;
28. 指针
单指针指向 值
双指针 指向 指针
intNsnumber
[dictionarysetObject:[NSNumbernumberWithInt:1] forKey:@"messageStatus*****ForBack"];
29. 好的电子书
iPhone 开发入门经典
美(johnray 著sean Johnson 袁国忠译)
人民邮电出版社
30. 简单的网络读出数据
NSString*userName1=[selfEncodeGB2312Str:username];
NSString*strUrl = [NSStringstringWithFormat:@"%@allFriend.asp?username=%@",ServerAddress,userName1];
NSMutableURLRequest*request = [[NSMutableURLRequestalloc] initWithURL:[NSURLURLWithString:strUrl]];
//[requestsetHTTPMethod:@"POST"];
NSData*returnData = [[NSDataalloc]initWithData:[NSURLConnectionsendSynchronousRequest:requestreturningResponse:nilerror:nil]];
[request release];
NSStringEncodingenc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString*returnString=[[NSStringalloc]initWithData:returnData encoding:enc];
[returnData release];
if([returnString length]>42) {
returnString=[returnStringsubstringFromIndex:42];
}
else{
NSLog(@"returnString数据不对");
}
NSError*error;
NSDictionary*dict= [XMLReaderdictionaryForXMLString:returnString error:&error];
returndict ;
31. 简体中文编码
NSStringEncodingenc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSString*returnString=[[NSStringalloc] initWithData:bufencoding:enc];
《斯坦福:iphone开发教程》[中英双语字幕]
http://v.163.com/special/opencourse/iphonekaifa.html
《斯坦福:iphone开发教程》[中英双语字幕]
更新至第10集
32. GDataXMLDocument 转成string类型
doc = [[GDataXMLDocumentalloc] initWithRootElement:element];
{
NSString *xmlStr = [[NSString alloc] initWithData:[doc XMLData]encoding:NSUTF8StringEncoding];
NSLog(@"%@", xmlStr);
[xmlStr release];
}
[doc release];
doc = nil;
33. 循环依赖
@classSmsProcessor;
CocoaData
NDGroup*group = [NDGroupAccessor groupWithID:groupID];
NSSet*set = [group unityMessages];
NSMutableArray*array = nil;
for(UnityMessage*msg inset) {
if(msg.msgType== SMS) {
[array addObject:msg];
}
}
34. 数据库操作
/**
Method to get smsesfrom group
@param groupID aunique identification of group
@returns a Sms ofNSArray
*/
- (NSArray*)smsesFromGroupID:(NSString*)groupID
{
if(groupID == nil) {
returnnil;
}
[selfresetLastError];
NSError*error = nil;
MegaFonModel*megaFonModel = [MegaFonModelsharedModel];
NSFetchRequest*fetchRequest =[[NSFetchRequestalloc] init];
NSEntityDescription*entity=[NSEntityDescription
entityForName:@"SMS"
inManagedObjectContext:megaFonModel.managedObjectContext];
[fetchRequest setEntity:entity];
//设置条件
NSPredicate*predicate = [NSPredicatepredicateWithFormat: @"(groupID = %@)",groupID];
[fetchRequest setPredicate:predicate];
NSArray*array = [megaFonModel.managedObjectContextexecuteFetchRequest:fetchRequest error:&error];
[fetchRequest release];
if(error) {
_lastError= [error retain];
array = nil;
}
if(!error&&[array count]>=1){
returnarray;
}
returnnil;
}
35. 改变scroolview的位置
[self.tableViewsetContentOffset:CGPointMake(0, 50.f) animated:NO];
36. 设置Button字体设置
UIButton*btn=[[UIButtonalloc] initWithFrame:CGRectMake(0, 0, 60, 50)];
[btn setTitle:@"124"forState:UIControlStateNormal];
btn.titleLabel.font=[UIFontsystemFontOfSize:19];
[self.viewaddSubview:btn];
37. UITextField
UITextField*fieldPwd=[[UITextFieldalloc] initWithFrame:CGRectMake(65, 40, 200, 25)];
fieldPwd.borderStyle=UITextBorderStyleRoundedRect;
fieldPwd.keyboardType=UIKeyboardTypeASCIICapable;
fieldPwd.secureTextEntry= YES;
fieldPwd.text=@"[email protected]";
[cell.contentViewaddSubview:fieldPwd];
[fieldPwdrelease];
fieldPwd=nil;
38. tableview下拉不上升
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[table_view setContentOffset:CGPointMake(0, 44) animated:NO];
NSIndexPath *tableSelection = [table_viewindexPathForSelectedRow];
[table_view deselectRowAtIndexPath:tableSelection animated:NO];
}
39. UIActionSheet
if (nil == as_select) {
as_select= [[UIActionSheet alloc] initWithTitle:nil delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"插入表情",@"转发",nil];
as_select.actionSheetStyle =UIActionSheetStyleAutomatic;
}
[as_select showInView:self.view];
40. 设置状态栏
Status Bar is InitiallyHidden:隐藏上面的状态栏,在.plist里添加项
Status Bar Style:状态栏样式
41. 渐变色
CAGradientLayer*gradientLaye = [[CAGradientLayer alloc] init];
[gradientLaye setFrame:CGRectMake(0, 100, 320, 100)];
//CAGradientLayer *gradientLayer = (CAGradientLayer*)self.layer;
gradientLaye.colors =
[NSArray arrayWithObjects:
/*
(id)[UIColorcolorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0].CGColor,
(id)[UIColorcolorWithRed:0.0 green:1.0 blue:0.0 alpha:1.0].CGColor,
(id)[UIColorcolorWithRed:0.0 green:0.0 blue:1.0 alpha:1.0].CGColor,
*/
(id)[UIColorcolorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0].CGColor,
(id)[UIColorcolorWithRed:0.45 green:0.45 blue:0.45 alpha:1.0].CGColor,
nil];
[gradientLaye setStartPoint:CGPointMake(0.0, 1.0)];
//[gradientLayer setEndPoint:CGPointMake(100, 100)];
[self.layer addSublayer:gradientLaye];
[gradientLaye release];
42. 隐藏Tabbar
CallingViewController*callingVC=[[CallingViewControlleralloc] init];
callingVC.hidesBottomBarWhenPushed=YES;
[self.navigationControllerpushViewController:callingVC animated:YES];
43. 得到触摸的位置
(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {UITouch* touch = [touches anyObject];CGPoint pt = [touch locationInView:self];printf("point = %lf,%lf\n", pt.x, pt.y);}
44. SearchBar 添加标题
asearchBar.prompt= @"输入字母、汉字或电话号码搜索";
45. 判断是否在View里
CGRectContainsPoint(imgVBlue.frame, position)
46. 把视图添加到最上方
[self.viewbringSubviewToFront:second];
47. 子视图
[btnsubviews]
48. 获得本地文件内容
NSString*filePath=[[NSBundlemainBundle]pathForResource:@"1"ofType:@"txt"];
NSString*str=[[NSStringalloc]initWithContentsOfFile:filePath];
NSLog(@"str=%@",str);
49. Property list的用法
读取plist
NSString*errorDesc = nil;
NSPropertyListFormatformat;
NSString*rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString*plistPath = [rootPath stringByAppendingPathComponent:@"untitled.plist"];
if(![[NSFileManagerdefaultManager] fileExistsAtPath:plistPath]) {
plistPath = [[NSBundlemainBundle] pathForResource:@"untitled"ofType:@"plist"];
}
NSData*plistXML = [[NSFileManagerdefaultManager] contentsAtPath:plistPath];
NSMutableDictionary*mudict = (NSMutableDictionary*)[[NSPropertyListSerializationpropertyListFromData:plistXMLmutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&errorDesc] retain];
NSArray* keysArr = [[[mudict allKeys] sortedArrayUsingSelector:@selector(compare:)] retain];
if(!mudict) {
NSLog(@"Error reading plist: %@, format:%d",errorDesc, format);
}
NSLog(@"keyarr ==%@",[keysArr objectAtIndex:0]);
50. 正则
英文字母数字下划线是:/^\w+$/;
汉字的是:/^[\u0391-\uFFE5]+$/;
51. 当前时间 计时
timebegin= [NSDatetimeIntervalSinceReferenceDate];
52. 越过tabbar添加view
[self.tabBarController.viewaddSubview:VGlide];
53. scrollview 向上移动
scrollVGlide.contentOffset=CGPointMake(0, 50);
54. 改变tabbar的背景颜色
UIImageView* img = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"bg.png"]];
img.frame= CGRectOffset( img.frame, 0, 1);
[tabBarCtr.tabBarinsertSubview:img atIndex:0];
[img release];
55. 如何隐藏状态栏
[ UIApplication sharedApplication].statusBarHidden = YES;
56. 获取本地的时区?
[NSTimeZonelocalTimeZone];
57. textview删除按钮
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)rangereplacementText:(NSString *)text{
NSLog(@"content is %@, range is %@, text is%@",textView.text,NSStringFromRange(range),text);
if ([text length]==0) {
NSLog(@"NO");
return NO;
}else {
return YES;
}
}
58. textview只现实 联想字
_inputTxtFeild.hidden=NO;// By Sunny 隐藏原来的
[[_inputTxtFeild.subviewsobjectAtIndex:0] setHidden:YES];
_inputTxtFeild.scrollEnabled=NO;
59. mac svn服务
SmartSVN
60. 断点调试
(gdb)pchatFrame
$1 = {
origin = {
x = 0,
y = 364
},
size = {
width = 320,
height = 57
}
}
61. Ps下载地址
http://soft.macx.cn/soft1265.htm
62. 橡皮擦 擦出imgView
CGPointcurrentPoint = [touch locationInView:imageView];
UIGraphicsBeginImageContext(imageView.frame.size);
[imageView.image drawInRect:imageView.bounds];
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(currentPoint.x, currentPoint.y, 30, 30));
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
63. uiview 设置圆角
UIImageView *v=[[UIImageView alloc]initWithFrame:CGRectMake(25, 25, 100, 100)];
v.image=[UIImage imageNamed:@"face01.png"];
[[v layer] setBorderWidth:2.0];//画线的宽度
[[v layer] setBorderColor:[UIColor blackColor].CGColor];//颜色
[[v layer]setCornerRadius:15.0];//圆角
v.backgroundColor=[UIColor redColor];
//[v.layer setCornerRadius:8.0];
[v.layer setMasksToBounds:YES];
[self.view addSubview:v];
[v release];
64. 创建 NSIndexPath
NSIndexPath*indexpath = [NSIndexPathindexPathForRow:0inSection:<#(NSUInteger)section#>];
65. actionSheet从下方弹出
[actionSheet showFromTabBar:self.tabBarController.tabBar];
[actionSheet showInView:[UIApplicationsharedApplication].keyWindow];
通过secion row 得到cell
uitableviewcell*cell=(uitableviewcell*)[tableView cellForRowAtIndexPath:indexPath];
66. 常用字体
[lblNamesetFont:[UIFontfontWithName:@"Helvetica-Bold"size:18.0]];
[lblContentsetFont:[UIFontfontWithName:@"Helvetica"size:14.0]];
Program received signal: “EXC_BAD_ACCESS”.: 内存释放过多
67. 隐藏键盘
UIView *v = [[[UIView alloc] initWithFrame:CGRectZero]autorelease];
[begintimesetInputView:v];
68. 父控制器 改变
self.parentViewController.arrAllUnityMsg= nil;
[self.navigationControllerpopViewControllerAnimated:NO];
- (void)allOnebox {
OneBoxFolderView* switchFolder = [[OneBoxFolderViewalloc] init];
switchFolder.myParentViewController= self;
switchFolder.hidesBottomBarWhenPushed= YES;
[self.navigationControllerpushViewController:switchFolder animated:YES];
[switchFolder release];
}
OneBoxViewController*_myParentViewController;
self.myParentViewController.arrAllUnityMsg= [[BusinessManagersharedManager].messageSearchManagergetOneBoxMessages];
[self.navigationControllerpopViewControllerAnimated:NO];
69. 枚举类型
typedefenum{
ShowAll= 0, //显示所有的联系人
SendMsg= 1, //发送信息
SendEmail= 2//发送邮件
} Sendtype; //在初始化时,需要制定发送的方式,在弹出
70. Iphone4 标准 字体
Arial 黑体 ,
71. 官方中文版的《iPhone人机界面指南》
72. 重新显示tabbar
NSMutableArray*list1 = [[NSMutableArrayalloc]init];
[list1 addObjectsFromArray:self.navigationController.viewControllers];
OneBoxViewController*oneboxCtr = [[OneBoxViewControlleralloc] initWithNibName:nilbundle:nil];
//[list1 removeLastObject];
//[list1 removeLastObject];
//[list1 removeLastObject];
[list1 removeAllObjects];
[list1 addObject:oneboxCtr];
self.navigationController.viewControllers= (NSArray*)list1;
[oneboxCtr release];
[list1 release];
73. svn调试
Last login: Mon Jul 25 10:42:35on ttys001
Sunnys-iMac:~ Sunny$ ls
Desktop Movies Sites
Documents Music 发送注册信息
Downloads Pictures
Library Public
Sunnys-iMac:~ Sunny$ cdDesktop/
Sunnys-iMac:Desktop Sunny$ ls
02-设计文档dial
123 tabbarTest.zip
123.zip trunk.zip
AllOfOneFriendController.rtf zhanghao.rtf
CoredataTest 文档
HWtrunk 加班.rtf
HWtrunk.zip 归档.zip
MobileHIG(iPhone 人机界面).pdf 自定义cell和coredata
QQ.rtf 未命名文件夹
RCS项目杂乱五章联系和好友主要字段.xlsx
coreData 小demo
Sunnys-iMac:Desktop Sunny$ cdHWtrunk
Sunnys-iMac:HWtrunk Sunny$ ls
[email protected] [email protected] ringbacktone.mp3
English.lproj Src ringtone.mp3
Images ThirdParty tap.aif
Libs UnitTest zh_CN.lproj
Model [email protected]
RCS.xcodeproj build
Sunnys-iMac:HWtrunk Sunny$ svncleanup
Sunnys-iMac:HWtrunk Sunny$
删除Xcode 命令
一条命令卸载Xcode和iPhone SDK
打开Terminal,输入以下代码并回车即可
sudo /Developer/Library/uninstall-devtools --mode=all