1、设置 imagepicker 的大小
imagepicker 在 popover controller 总是以默认大小显示,设置 popovercontentsize 属性似乎无用。解决办法是将imagepicker “包含”到一个定制的 viewcontroller 中,然后再 presentpopover 这个 viewcontroller :
uiviewcontroller *containercontroller = [[uiviewcontroller alloc] init];
containercontroller.contentsizeforviewinpopover = cgsizemake(600,self.view.frame.size.height);
[containercontroller.viewaddsubview:_imagepicker.view];
_popcontroller= [[uipopovercontroller alloc] initwithcontentviewcontroller:containercontroller];
cgpoint p=[self.view convertpoint:button.center
fromview:sender.superview];
[_popcontroller presentpopoverfromrect:(cgrect){p,cgsizezero}
inview:self.view
permittedarrowdirections:uipopoverarrowdirectionany
animated:yes];
[_imagepicker.view setframe:containercontroller.view.frame];// 很重要
注意,popover的宽度最多600。此外,_imagepicker 每次 presentpopoverfromrect 之前都必须 init一次,否则显示位置不正确。
2、上传文件中文文件名乱码问题
在ios客户端将文件名用url encode编码,然后在服务端用url decode解码。
客户端:
nsstringencodingenc=nsutf8stringencoding;
[request setdata:datawithfilename [filename stringbyaddingpercentescapesusingencoding:enc]
andcontenttype:@"application/octet-stream" forkey:key];
服务端:
string filename=request.getparameter(“upload_file”);
filename=urldecode.decode(s,”utf-8”);
3、mac 64 bit device
有时从svn更新工程后,scheme会显示为mac 64 bit device,并且不允许运行程序。这时只需要重新设置一下target的deploymenttarget就好(设置为模拟器或调试设备)。
4、去除调试程序的nslog
编译参数optimize level根据不同的版本设置。例如对于debug版本是none,对于release版本是fastest,smallest。这样,我们可以根据这个参数来重新定义nslog函数:
#ifndef __optimize__
#define nslog(...)nslog(__va_args__)
#else
#define nslog(...) {}
#endif
5、警告:no previous prototye for function
根据c规范, 如果函数没有参数,使用void作为函数参数。
函数声明应使用 “void functiona(void);”,而不能是”void functiona();”.
6、数组排序
方法一:
- (nscomparisonresult)compare:(person *)otherobject {
return [self.birthdatecompare:otherobject.birthdate];
}
nsarray *sortedarray;
sortedarray = [drinkdetails sortedarrayusingselector:@selector(compare:)];
方法二:
nssortdescriptor *sortdescriptor;
sortdescriptor = [[[nssortdescriptor alloc]initwithkey:@"birthdate"
ascending:yes] autorelease];
nsarray *sortdescriptors = [nsarray arraywithobject:sortdescriptor];
nsarray *sortedarray;
sortedarray = [drinkdetails sortedarrayusingdescriptors:sortdescriptors];
方法三( 10.6+):
nsarray *sortedarray;
sortedarray = [drinkdetails sortedarrayusingcomparator:^(id a, id b) {
nsdate *first =[(person*)a birthdate];
nsdate *second =[(person*)b birthdate];
return [firstcompare:second];
}];
7、xcode 4的build目录在哪里?
xcode 4 做了许多改变。你将不能找到build目录,你也无法找到products文件组。那么它把项目编译后生成的可执行文件放在哪里了呢?答案就是“{username}/library/developer/xcode/deriveddata/{project_name_and_random_crap}/build/products/{build_type}/{project_name}.app”目录。
8、警告:no rule to process file
xcode试图侦测每一种文件的类型。当它认为文件属于“源文件”类型(比如.js文件),总是试图将它加到 compile sources中并试图编译。解决这个警告的办法是,把这类文件从build phases的 compile sources移到 copy bundle resources中。
9、警告:'initwithframe:reuseidentifier:'is deprecated
该方法在后续版本中将被抛弃。请使用
- initwithstyle:reuseidentifier:
10、itms-services不工作
itms-services 被apple/iphone识别为一个特殊的字眼,它会校验provisioning profile中指定的证书并进行安装。
在安装这个.ipa文件前,要校验profisioning profile,这会连接到 ax.init.itunes.apple.com和 ocsp.apple.com。
如果你处于intranet中,请检查是否可访问上述地址。如果不能,你将无法使用ota来安装应用程序。要求ios 4.0以上。
注:上述地址不能访问并不会影响安装。但是ios会在运行时通过上述地址检查证书是否合法,如果安装是合法的,ios会缓存检查结果(7天)。
以上就是ios 开发百问(1)的内容。