码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 开发百问(6)

时间:2014-09-02 12:23:14      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   os   io   使用   java   ar   for   

61、警告“addexplicit braces to avoid dangling else”

所谓“危险的else”是类似这样的代码:

if(a== 10)

printf("TEN");

else

printf("NOT TEN");

a = 100;

编译器认为你的else 子句导致语义不清,你到底是什么意思?是无论 a 是否等于10 , if 执行完之后都要将 a 赋值为100,还是只想在 else 子句(即 a 不等于10 的时候)中将 a 赋值为 100?

如果是前者,正确的写法应该是:

if(a== 10) {

printf("TEN");

}else{

printf("NOT TEN");

}

a= 100;

如果是后者,正确的写法应该是:

if(a== 10) {

printf("TEN");

}else{

printf("NOT TEN");

a = 100;

}

当然,对于c/c++/java 编译器来说,这只是一个小问题,并不会导致无法编译。编译器实际上是倾向于前者的,它自动按第一种情况处理。但它会警告你这是一种不好的代码风格,你可以用#pragma clang diagnostic ignored "-Wswitch" 宏忽略该警告,或者将编译选项 MissingBraces and Parentheses 设置为 NO。

62、iPad模拟器不显示 Home 键

从Xcode 4.3 开始,为了获得更大的用户可用空间,iPad 模拟器不显示 Home 键。 你可以通过菜单“ 硬件 > 首页”或者快捷键??H 来代替 Home 键。

63、Novisible @interface for ‘NSURL‘ declares the selector ‘query‘

iOS6 中,该方法被抛弃,请用 NSURL+Parameters 替代。

64、certificateidentity ‘iphone distribution‘ appears more than once

这是证书重复的错误,需要将钥匙串里重复的证书删掉编译才能通过。但是,如果你重启Xcode ,会发现之前删除的证书又回来了。但当重新启动Xcode时,Xcode里的证书会被导进钥匙串,所以仅仅是删除钥匙串中重复证书是无效的。

相信 许多同学对 Xcode 的这个 Bug 深恶痛绝了,但除了反复地(但是徒劳地)从钥匙串中删除证书,也没有别的办法了。其实,也不能光怪 Xcode,而是跟”iPhone 配置使用工具“也有一定的关系。

 

Xcode中的这些“残留”证书不以常规的形式存在。如果你安装了“iPhone 配置实用工具”,这些证书实际上存在于/Users/km-cn/Library/MobileDevice/Applications/目录下的.app 文件中,这些.app 实际上是 “iPhone配置实用工具”——“应用程序”中的所导入的 app。你可以用Finder ——“显示包内容”来查看.app 。其中一个名叫“embedded.mobileprovision”的文件,就是“残留”的重复证书。你可以逐一删除这些 .app,也可以干脆把该目录下的所有.app 都删除(反正只要项目文件存在,你随时可以编译出这些 .app并导入到“iPhone 配置实用工具”中)。最后,还要将 Orgnizer 中的重复证书也删除,然后重启Xcode。

65、Application Identifier ‘com. ydtf.*‘ which doesn‘t match the current setting‘com.ydtf.dlt‘

如你所见,这两个Application ID 绝对是匹配的(*表示通配符)。但这个莫名的错误会导致你始终不能编译。这绝对是 Xcode 的另一个 Bug,先将 CodeSigning 修改为 Don‘t Code Sign,Build,然后再修改回正确的签名 Build。

66、Theidentity used to sign the executable is no longer valid.

由于前面的签名问题导致不能Archive。解决方式见问题 65。

67、在iPad 中使用 presentModalViewController 设置弹出窗口的大小

TestViewController*testVC = [[TestViewController alloc] initWithNibName:@"TestViewController"bundle:nil];

    testVC.modalPresentationStyle= UIModalPresentationFormSheet;

    testVC.modalTransitionStyle= UIModalTransitionStyleCrossDissolve;

    [selfpresentModalViewController:testVC animated:YES];

    testVC.view.superview.frame= CGRectMake(0, 0, 649, 397);//it‘s important to do this afterpresentModalViewController

   testVC.view.superview.center = self.view.center;

注意://it‘simportant to do this after presentModalViewController。即一定要在[selfpresentModalViewController:testVC animated:YES];之后设置frame的大小!

 

68、在iPad 中定制 ActionSheet  的按钮和Popover 箭头方向。

ActionSheet在 iPad 上以Popover的方式显示。默认不会显示cancelButton(SDK用Popover之外的区域代替cancelButton,用户只要点击Popover之外的区域就等同点击取消按钮)。如果你这样init一个ActionSheet:

UIActionSheet* sheet=[[UIActionSheet alloc]initWithTitle:nil

                                                   delegate:self

                                          cancelButtonTitle:@"cancel"

                                     destructiveButtonTitle:@"ok"

                                          otherButtonTitles:nil];

则最终只有红色的destructiveButton 会显示。

如果你非要显示cancelButton,则可以这样干:

UIActionSheet* sheet=[[UIActionSheet alloc]initWithTitle:nil

                                                   delegate:self

                                          cancelButtonTitle:nil

                                     destructiveButtonTitle:nil

                                          otherButtonTitles:@"cancel",@"ok",nil];

//    sheet.cancelButtonIndex=0;

sheet.destructiveButtonIndex=1;

指定destructiveButtonIndex之后,该按钮被显示为红色。

但千万不要指定cancelButtonIndex,因为在iPad上cancelButton会被移除。

在iPad中,SDK没有提供可以修改 actionSheet 的箭头方向的API,系统自动判断箭头显示的方向。但我们可以利用showFromRect的第1个参数来改变箭头的方向:

CGRect r=sender.bounds;

    r.size.width=2*self.view.bounds.size.width;

    r.origin.x=-self.view.bounds.size.width+sender.bounds.size.width/2+sender.frame.origin.x;

    [sheet showFromRect:r inView:sender animated:YES];

这样就将原来的左箭头,换成了上箭头。

其实iOS 在判断 actionSheet 弹出方向时的逻辑很简单,哪边有“足够”的空间,它就往哪边弹出。当我们利用showFromRect的第1个参数将3个方向都“堵死”后,它就只能老老实实地从我们想要的方向弹出了。

69、在 ASINetworkQueue 中 setShowAccurateProgress=YES 不起作用

在 networkQueue.showAccurateProgress= YES之前加入 request.showAccurateProgress= YES ,否则showAccurateProgress 不会生效。示例代码:

equest.showAccurateProgress=YES;

networkQueue.showAccurateProgress=YES;

[networkQueue setSuspended:YES];

[networkQueue addOperation:request];

networkQueue.uploadProgressDelegate=self;

[networkQueue go];

此外,由于 CFNework 中的一个 Bug,对于小于128K的数据,无法跟踪其上传/下载的精确进度。

70、如何设置 UIWebView 背景色为透明?

在IB中设置 UIWebView 的 Background 属性为 Clear Color 并不能使其背景透明。要达到这个目的,你需要使用以下两句:

[webView setBackgroundColor:[UIColor clearColor]];

[webView setOpaque:NO];

 

iOS 开发百问(6)

标签:des   style   color   os   io   使用   java   ar   for   

原文地址:http://blog.csdn.net/kmyhy/article/details/39004259

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!