zoukankan      html  css  js  c++  java
  • iOS 开发百问(6)

    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  的button和Popover 箭头方向。

    ActionSheet在 iPad 上以Popover的方式显示。默认不会显示cancelButton(SDK用Popover之外的区域取代cancelButton,用户仅仅要点击Popover之外的区域就等同点击取消button)。假设你这样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之后,该button被显示为红色。

    但千万不要指定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 弹出方向时的逻辑非常easy,哪边有“足够”的空间,它就往哪边弹出。当我们利用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];

  • 相关阅读:
    Attach Files to Objects 将文件附加到对象
    Provide Several View Variants for End-Users 为最终用户提供多个视图变体
    Audit Object Changes 审核对象更改
    Toggle the WinForms Ribbon Interface 切换 WinForms 功能区界面
    Change Style of Navigation Items 更改导航项的样式
    Apply Grouping to List View Data 将分组应用于列表视图数据
    Choose the WinForms UI Type 选择 WinForms UI 类型
    Filter List Views 筛选器列表视图
    Make a List View Editable 使列表视图可编辑
    Add a Preview to a List View将预览添加到列表视图
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5118793.html
Copyright © 2011-2022 走看看