iphone some tipsWord文件下载.docx

上传人:b****5 文档编号:18595827 上传时间:2022-12-29 格式:DOCX 页数:10 大小:55.04KB
下载 相关 举报
iphone some tipsWord文件下载.docx_第1页
第1页 / 共10页
iphone some tipsWord文件下载.docx_第2页
第2页 / 共10页
iphone some tipsWord文件下载.docx_第3页
第3页 / 共10页
iphone some tipsWord文件下载.docx_第4页
第4页 / 共10页
iphone some tipsWord文件下载.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

iphone some tipsWord文件下载.docx

《iphone some tipsWord文件下载.docx》由会员分享,可在线阅读,更多相关《iphone some tipsWord文件下载.docx(10页珍藏版)》请在冰豆网上搜索。

iphone some tipsWord文件下载.docx

no"

NO"

YES"

yes"

nil];

NSPredicate*predicate=[NSPredicatepredicateWithFormat:

SELFIN{'

0'

'

no'

NO'

}"

];

NSArray*result=[arrfilteredArrayUsingPredicate:

predicate];

result);

for(NSString*sinarr){

%@:

%d"

s,[predicateevaluateWithObject:

s]);

5.FromNSStringtoNSData

NSString*text=@"

Somestring"

;

NSData*data=[textdataUsingEncoding:

NSUTF8StringEncoding];

6.FromNSDatatoNSString

NSString*text=[[NSStringalloc]initWithData:

dataencoding:

7.日期和时间

NSCalendar*gregorian=[[NSCalendaralloc]initWithCalendarIdentifier:

NSGregorianCalendar];

NSDateComponents*todayComponents=[gregoriancomponents:

(NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit)yourDate];

NSIntegertheDay=[todayComponentsday];

NSIntegertheMonth=[todayComponentsmonth];

NSIntegertheYear=[todayComponentsyear];

//nowbuildaNSDateobjectforyourDateusingthesecomponents

NSDateComponents*components=[[NSDateComponentsalloc]init];

[componentssetDay:

theDay];

[componentssetMonth:

theMonth];

[componentssetYear:

theYear];

NSDate*thisDate=[gregoriandateFromComponents:

components];

[componentsrelease];

//nowbuildaNSDateobjectforthenextday

NSDateComponents*offsetComponents=[[NSDateComponentsalloc]init];

[offsetComponentssetDay:

1];

NSDate*nextDate=[gregoriandateByAddingComponents:

offsetComponentstoDate:

yourDateoptions:

0];

[offsetComponentsrelease];

[gregorianrelease];

8.使用performSelectorInBackground(多线程)调用的方法,必须在该方法中用NSAutoreleasePool

否则出现错误:

nopoolinplace-justleaking。

如果用performSelector则没有这个问题。

9.ld:

symbol(s)notfound错误的解决办法

展开"

Targets-->

CompileSources"

,查看列出的所有.m文件,找出其中缺失的.m文件,拖到其中。

10.OjbectC让线程休眠

[NSThreadsleepForTimeInterval:

2];

//单位是秒

11.nil和NULL的区别

在ObjectC中,NULL和nil都是空指针,不同的是,NULL用于c指针,即(void*);

而nil用于c++或java对象,即id为空

12.字符串替换

str=[strstringByReplacingOccurrencesOfString:

[]"

withString:

13.assign,copy,retain之间的区别

∙assign:

简单赋值,不更改索引计数(ReferenceCounting)。

∙copy:

建立一个索引计数为1的对象,然后释放旧对象

∙retain:

释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1

retain的实际语法为:

-(void)setName:

(NSString*)newName{

if(name!

=newName){

[namerelease];

name=[newNameretain];

//name’sretaincounthasbeenbumpedupby1

说了那么麻烦,其实接下来的话最重要:

?

如果你不懂怎么使用他们,那么就这样->

∙使用assign:

对基础数据类型(NSInteger,CGFloat)和C数据类型(int,float,double,char,等等)

∙使用copy:

对NSString

∙使用retain:

对其他NSObject和其子类

14.nonatomic关键字:

atomic是Objc使用的一种线程保护技术,基本上来讲,是防止在写未完成的时候被另外一个线程读取,造成数据错误。

而这种机制是耗费系统资源的,所以在iPhone这种小型设备上,如果没有使用多线程间的通讯编程,那么nonatomic是一个非常好的选择。

15.发送短信/邮件/打电话

+(void)alert:

(NSString*)msg

{

UIAlertView*alertView=[[[UIAlertViewalloc]initWithTitle:

msgmessage:

delegate:

selfcancelButtonTitle:

OK"

otherButtonTitles:

nil,nil]autorelease];

[alertViewshowWithBackground];

+(NSString*)cleanPhoneNumber:

(NSString*)phoneNumber

NSString*number=[NSStringstringWithString:

phoneNumber];

NSString*number1=[[[numberstringByReplacingOccurrencesOfString:

"

]

//stringByReplacingOccurrencesOfString:

-"

stringByReplacingOccurrencesOfString:

("

]

)"

returnnumber1;

+(void)makeCall:

(NSString*)phoneNumber

if([DeviceDetectionisIPodTouch]){

[UIUtilsalert:

kCallNotSupportOnIPod];

return;

NSString*numberAfterClear=[UIUtilscleanPhoneNumber:

NSURL*phoneNumberURL=[NSURLURLWithString:

[NSStringstringWithFormat:

tel:

numberAfterClear]];

makecall,URL=%@"

phoneNumberURL);

[[UIApplicationsharedApplication]openURL:

phoneNumberURL];

+(void)sendSms:

kSmsNotSupportOnIPod];

sms:

sendsms,URL=%@"

+(void)sendEmail:

mailto:

phoneNumber]];

(NSString*)tocc:

(NSString*)ccsubject:

(NSString*)subjectbody:

(NSString*)body

NSString*str=[NSStringstringWithFormat:

%@?

cc=%@&

subject=%@&

body=%@"

to,cc,subject,body];

str=[strstringByAddingPercentEscapesUsingEncoding:

[NSURLURLWithString:

str]];

16.将NSString转换编码集为gb2312

NSURL*url=[NSURLURLWithString:

urlStr];

NSData*data=[NSDatadataWithContentsOfURL:

url];

NSStringEncodingenc=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);

NSString*retStr=[[NSStringalloc]initWithData:

enc];

17.将指定格式的字符串转换为日期类型

//把yyyyMMddHHmmss格式的字符串转换为NSDate类型

-(NSDate*)stringToDate:

(NSString*)dateString{

NSDateFormatter*dateFormatter=[[NSDateFormatteralloc]init];

[dateFormattersetDateFormat:

yyyyMMddHHmmss"

NSDate*date=[dateFormatterdateFromString:

dateString];

[dateFormatterrelease];

returndate;

18."

Arraywasmutatedwhilebeingenumerated"

问题的解决

在操作数组对象时进行同步,如:

@synchronized(enemiesArray){

⋯⋯

数组操作代码

⋯⋯}

19、字符串与数组之间的转换:

SString*string=@"

one:

two:

three:

four"

NSArray*result=[stringcomponentsSeparatedByString:

:

string=[resultcomponentsJoinedByString:

_"

20、定时器NSTimer//1秒后,触发定时器事件

NSTimer*timer=[NSTimerscheduledTimerWithTimeInterval:

1.0target:

self

selector:

@selector(timerFired)userInfo:

nilrepeats:

NO];

21、让UITextField里面的text垂直居中可以这样写:

text.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;

22、在UITextField最右侧加图片是以下代码,

UIImageView*imgv=[[UIImageViewalloc]initWithImage:

[UIImageimageNamed:

right.png"

]];

text.rightView=imgv;

text.rightViewMode=UITextFieldViewModeAlways;

如果是在最左侧加图片就换成:

text.leftView=imgv;

text.leftViewMode=UITextFieldViewModeAlways;

23、NSLog的格式化字符串

%@对象

%%百分号

%d,%i整数

%u无符整形

%f浮点/双字

%x,%X二进制整数

%o八进制整数

%zusize_t

%p指针

%e浮点/双字(科学计算)

%g浮点/双字

%sC字符串

%.*sPascal字符串

%c字符

%Cunichar

%lld64位长整数(longlong)

%llu无符64位长整数

%Lf64位双字

24、直接链接到itunes

NSURL*url=[NSURLURLWithString:

itms-apps:

//

[[UIApplicationsharedApplication]openURL:

直接链接到safari网页

25、获取Bundle的版本号

NSString*localVersion=[[[NSBundlemainBundle]infoDictionary]objectForKey:

CFBundleVersion"

26、stray'

\357'

inprogram

错把'

['

写成中文的方括号'

['

了。

27、provisioningprofile'

xxx'

can'

tbefound

如果你更新了profile,再编译iphone项目,发现下面的错误,那你无论如何clean也不会成功,那真是让人恼火阿

这时候,先copy上面那行出错信息中的profileidentifier,比如:

86C90BA7-77B6-4A75-9EAD-A1FD88C17F6D

然后关闭这个项目,打开finder到你的项目文件xxxx.xcodeproj上面按鼠标右键,选择ShowPackageContents菜单。

在新打开的finder的,找到project.pbxproj,使用一个文本edit打开它,用查找功能找到所有的有那行编码的位置,删除那一行:

PROVISIONING_PROFILE[sdk=iphoneos*]"

="

86C90BA7-77B6-4A75-9EAD-A1FD88C17F6D"

删除以后,保存这个project.pbxproj文件,用xcode重新打开你的项目,再编译一下试试

28、获取设备类型及当前方向

if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){//如果设备为iPad

//获取设备当前方向,及时进行旋屏

UIInterfaceOrientationorientation=[[UIDevicecurrentDevice]orientation];

[selfwillAnimateRotationToInterfaceOrientation:

orientation

duration:

}

29、打印UIView的subviews

-(void)explode:

(id)aViewlevel:

(int)aLevel{

for(inti=0;

i<

aLevel;

i++)

printf("

);

%s:

%s\n"

[[[aViewclass]description]UTF8String],[[[aViewsuperclass]description]UTF8String]);

for(UIView*subviewin[aViewsubviews])

[selfexplode:

subviewlevel:

(aLevel+1)];

使用:

[selfexplode:

textviewlevel:

30、旋屏后20像素bug的解决

没有优雅的解决方案,只有在view显示后,手动调整:

mainView.frame=CGRectMake(0,

0-20,

self.view.frame.size.width,

self.view.frame.size.height+20);

31、安装Xcode3.2后安装Xcode4.2出现错误:

error:

unabletocreate'

/Users/km-cn/Library/Developer/Xcode/DerivedData/MOA-dwztpffnaapnqfevxsfxemqawqdi/Build/Intermediates'

(Permissiondenied)

使用chmod命令:

sudochmod-R777/Users/km-cn/Library/Developer/

32、'

UIKeyboardBoundsUserInfoKey'

isdeprecated警告

将:

NSValue*aValue=[infoobjectForKey:

UIKeyboardBoundsUserInfoKey];

修改为:

UIKeyboardBoundsUserInfoKey"

32、退出程序

exit(EXIT_SUCCESS);

abort();

这个是undocument的,随时可能不可用。

33、'

isdeprecated

简单地用

NSValue*value=[infoobjectForKey:

替换掉:

34、缩放网页内容以适应UIWebView

NSString*jsCommand=[NSStringstringWithFormat:

document.body.style.zoom=0.40;

[webViewstringByEvaluatingJavaScriptFromString:

jsCommand];

或者

webView.scalesPageToFit=YES;

两个方法只能选择其中之一,前者不支持多点触摸缩放,后者支持——但它的自适应缩放不是很好,看起来页面总是要比屏幕真实尺寸要小一点,解决办法是,在html页面中加入:

<

metaname="

viewport"

content="

width=320"

/>

35、使TextField被编辑时,键盘不弹出

设置TextField的delegate,同时实现UITextFieldDelegate中的textFieldDidBeginEditing方法,并在其中加入[textFieldresignFirstResponder]。

如果是TextView,要实现UITextViewDelegate中的textViewDidBeginEditing方法。

36、定义常量

声明

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1