iOS 开发百问(5)

42、 警告:Multiplebuild commands for output file

target引用了名字反复的资源

找到当前的target,展开之后。找到CopyBundle Resources栏目。然后在里面找到反复名字的资源。删除不要的那个就可以

43、签名错误:Provisioningprofile can't be found

在Xcode中当你在更新了你得证书而再又一次编译你的程序,真机调试一直会出现Code Sign error: Provisioning profile ‘XXXX’ can't be found是不是会另你非常恼火。以下说说解决方法,让你非常好的解决问题。

 1.关闭你的项目。找到项目文件XXXX.xcodeproj,在文件上点击右键。选择“显示包内容”(ShowPackage Contents)。会新打开一个Finder。注:事实上XXXX.xcodeproj就是一个目录,这里新打开的一个Finder里面的三个文件就是该XXXX.xcodeproj目录里面的文件。

2.在新打开的Finder中找到project.pbxproj。而且打开。在这之中找到你之前的证书的编码信息。我之前报的错误信息是:

CodeSign error: Provisioning profile '37D44E7F-0339-4277-9A82-C146A944CD46',所以我用查找的方式找到了全部包含37D44E7F-0339-4277-9A82-C146A944CD46的行。而且删除。

3.保存,又一次启动你的项目。再编译。

就OK了。

44、 升级至Xcode 4.6 后导致 arc4random_uniform 不可用

当项目升级至Xcode4.6后出现编译错误:

Useof undeclared identifier 'arc4random_uniform'; did you mean 'arc4random_stir'?

似乎SDK 6.1 并不支持'arc4random_uniform',换成'arc4random'后问题解决。

45、升级Xcode4.6后,出现编译错误:Undefinedsymbols for architecture x86_64: "_OBJC_CLASS_$_NSMutableOrderedSet"

在build settings 中。设置 "Implicitly link Objective-C Runtime Support" 为NO,问题解决。

46、升级Xcode4.6后。出现警告:function'sleep' is invalid in C99

#import<unistd.h> 后解决。升级Xcode4.6后,很多头文件默认并没有被自己主动导入。比方 stdlib.h 和 unistd.h。

47、编译错误: autolayout on ios versions prior to 6.0

在Xcode 4.6 中编译Target 4.0的app时出现此问题(真机调试。设备为3GS,升级至iOS 6.1.3)。找到报错的.xib 文件。在Document面板中j将“UseAutolayout”(见下图)禁用。

48、怎样设置buttonTitleLabel 的文字对齐?

设置contentHorizontalAlignment 属性:

emailBtn.contentHorizontalAlignment= UIControlContentHorizontalAlignmentLeft;

或者用contentEdgeInset 调整文字边距(0表示不正确齐):

emailBtn.contentEdgeInsets= UIEdgeInsetsMake(0, 10, 0, 0);

或者二者结合同一时候使用。

49、错误:errorDomain=UA_ASIHTTPRequestErrorDomain Code=8 "Failed to move file from

Theerror happens after the file is downloaded; but before the file is successfullymoved from the tmp location to the Cache location

发生错误在文件下载到暂时文件。但还未移动到documents目录之前(能够用iExplorer查看到暂时文件的存在)。

使用“[requestsetShouldAttemptPersistentConnection:NO];”解决此问题。

50、编译错误:“hasbeen modified since the precompiled header was built”

  预编译头的时候文件被改动。Clean一下再又一次编译。

51、错误Could not change excutable permissions on the application

无法在iPhone上以同一个 AppID 安装两个不同的应用程序。通常是在Xcode 中运行 Project-->Profile命令时出现故障。由于一般真机调试时会在iPhone上装一个debug 应用程序,运行 Project-->Profile 后又会向iPhone上再次安装这个程序。两个程序的 AppID自然是相同的。于是出现上述错误。解决的方法:先删除iPhone上的那个程序。再运行Project-->Profile 命令。

52、Instruments错误:Targetfaild to run,例如以下图所看到的。


点击菜单条Scheme 的左下角。选择“Edit Scheme...”,在弹出窗体左側边栏选中“Profile xxx.app”,将其“BuildConfiguration”从“Release”改动为 “Debug”。

53、查看指针所指向的对象

假设知道地址,能够用GDB命令打印该地址所代表的对象。比如:

 po 0x1fba2e20

假设该指针不是一个对象,用:

p0x1fba2e20

54、Xcode 打包时 skip install的问题

总结:在自身project里面须要将skipinstall 设置为NO, 在引入其它静态库文件的project中skip install 设置为YES,否则在 Orgnizer 中无法公布你的程序。

-主App是须要部署的。所以不要将Skip Install设为YES, 仅仅须要改依赖项目。

55、错误: Pushinga navigation controller is not supported

SDK不同意直接在一个 NavigationController 中 push 一个 NavigationController。你能够用这句代码取代:

[self.navigationControllerpushViewController:nc.topViewController animated:YES];

56、为什么当用户点击Tab bar 上的button,总是会显示所选 NavigationController 的 rootViewController?

你能够为TabBarController 指定一个delegate 属性,并在 delegate 对象中实现 UITabBarControllerDelegate 托付:

#pragma mark TabBarController Delegate

- (BOOL)tabBarController:(UITabBarController *)tabBarControllershouldSelectViewController:(UIViewController *)viewController {

    UIViewController *tbSelectedController= tabBarController.selectedViewController;

    

    if ([tbSelectedController isEqual:viewController]) {

        return NO;

    }

    

    return YES;

}

57、使用setTitle 不能刷新 NavigationBar 的标题文本

有时候使用ViewController的 setTitle 方法并不能刷新 NavigationBar 的 title文本。极大的可能是你使用相似的代码定制了 titleView:

UILabel* label = [[[UILabel alloc] init] autorelease];

label.backgroundColor=[UIColor clearColor];

label.text = self.title;

label.font = [UIFont systemFontOfSize: 20];

……

[self.navigationItem setTitleView: label];

假设这样。你须要用相同的代码又一次定制titleView,才干刷新 NavigationBar title。或者,使用默认的 TitleView 而不要去定制它。

58、 nested push animation can result in corrupted navigation bar……

假设你在代码中连续多次(两次以上)pushViewController。会出现以上信息,这既不是错误也不少警告,仅仅是控制台输出的信息,但它会导致一些潜在的问题,比方NavigationController 的栈错误(比方用户有时候必须连按两次 backButton 才干返回上级视图)。往往还会伴随有例如以下信息的输出:

Unbalancedcalls to begin/end appearance transitions <FirstViewController: 0x2a2c00>

所谓连续多次,是指至少有一次push 是不经过用户交互而直接代码调用的。比如,当用户点击一个 TableViewCell,弹出一个 ViewController。然后在这个ViewController 的 viewDidLoad 方法或 viewWillAppear 方法中用代码 Push 还有一个 ViewController。这第二次push 并非由用户动作而是由代码触发的,因此会导致上述问题。

解决的方法是,在第二次push 时,将 animated 參数设置为 NO。

59、真机能够运行,模拟器不行

有时候出现模拟器不能调试的情况,程序一运行就退出,而且模拟器似乎“卡死”掉了。仅仅出现一个黑黑的窗体。按Home键也没有作用。

可是在真机上程序却能够运行。

这个问题的解决办法未知。但有一个解决方案是:在还有一个project中打开模拟器。然后在模拟器中把有问题的程序删除就可以。

60、警告“numeration not handledin switch

新的Apple LLVM compiler 4.0中,会对 switch 变量进行检查。假设该变量为枚举类型,则须要处理全部的枚举值。你能够加入一个 default:break;语句表示全部未列举的枚举值已处理。或者将编译选项"Check switch statements"设置为NO。

也能够用下列宏忽略switch 检查:

#pragmaclang diagnostic push

#pragmaclang diagnostic ignored "-Wswitch"

     ...<switchstatment>...

#pragmaclang diagnostic pop


原文地址:https://www.cnblogs.com/yfceshi/p/6978856.html