iOS 开发百问(5)

黄舟
Release: 2023-03-05 06:32:01
Original
1259 people have browsed it

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'?
Copy after login

似乎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 后解决。升级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、如何设置按钮TitleLabel 的文字对齐?
设置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,如下图所示。
438.jpg



点击菜单栏Scheme 的左下角,选择“Edit Scheme...”,在弹出窗口左侧边栏选中“Profile xxx.app”,将其“BuildConfiguration”从“Release”修改为 “Debug”。
53、查看指针所指向的对象
如果知道地址,可以用GDB命令打印该地址所代表的对象,例如:
po 0x1fba2e20
如果该指针不是一个对象,用:
p0x1fba2e20
54、Xcode 打包时 skip install的问题
总结:在自身工程里面需要将skipinstall 设置为NO, 在引入其他静态库文件的工程中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 上的按钮,总是会显示所选 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;
}
Copy after login

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];
Copy after login

如果这样,你需要用同样的代码重新定制titleView,才能刷新 NavigationBar title。或者,使用默认的 TitleView 而不要去定制它。
58、 nested push animation can result in corrupted navigation bar……
如果你在代码中连续多次(两次以上)pushViewController,会出现以上信息,这既不是错误也不少警告,只是控制台输出的信息,但它会导致一些潜在的问题,比如NavigationController 的栈错误(比如用户有时候必须连按两次 backButton 才能返回上级视图)。往往还会伴随有如下信息的输出:
Unbalancedcalls to begin/end appearance transitions
所谓连续多次,是指至少有一次push 是不经过用户交互而直接代码调用的。例如,当用户点击一个 TableViewCell,弹出一个 ViewController,然后在这个ViewController 的 viewDidLoad 方法或 viewWillAppear 方法中用代码 Push 另一个 ViewController。这第二次push 并不是由用户动作而是由代码触发的,因此会导致上述问题。
解决办法是,在第二次push 时,将 animated 参数设置为 NO。
59、真机可以执行,模拟器不行
有时候出现模拟器不能调试的情况,程序一运行就退出,而且模拟器似乎“卡死”掉了,只出现一个黑黑的窗口,按Home键也没有作用。但是在真机上程序却可以运行。这个问题的原因未知,但有一个解决方式是:在另一个工程中打开模拟器,然后在模拟器中把有问题的程序删除即可。
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"......
#pragmaclang diagnostic pop
Copy after login


以上就是iOS 开发百问(5)的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!