首頁  >  文章  >  後端開發  >  iOS 開發百問(5)

iOS 開發百問(5)

黄舟
黄舟原創
2017-01-20 09:34:331345瀏覽

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-427146A1 。
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',換成後解決問題。
45、升級Xcode4.6後,出現編譯錯誤:Undefinedsymbols for architecture x86_64: "_OBJC_CLASS_$_NSMutableOrderedSet"
在 Sbuild settings 中,設定 "Implicitly link Object-Ctime Sbuild settings 中,設定 "Implicitly link Object-Ctime,link
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 的文字對齊?
設定contentHorizo​​​​ntalAlignment 屬性:
emailBtn.contentHorizo​​​​ntalAlignment= UIControlContentHorizo​​​​ntalAlignmentLeft;
或用contentEdgeInset 調整文字邊距(0表示不對齊):
emailBtn.contentEdgeInsets=50,000); 。
49、錯誤:errorDomain=UA_ASIHTTPRequestErrorDomain Code=8 "Failed to move file from
Theerror happens after the file is downloaded; but before the file is successfmoved from the tully loved from the tache to the Cache但還未移動到documents目錄之前(可以用iExplorer查看到臨時檔案的存在)。
使用「[requestsetShouldAttemptPersistentConnection:NO];」解決此問題。

預編譯頭的時候檔案被修改。中執行Project-->Profile命令時出現問題。是相同的,於是出現上述錯誤。



点击菜单栏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;
}

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 945a7024ddbf9cc99e307517a118c7e1
所谓连续多次,是指至少有一次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"...<switchstatment>...
#pragmaclang diagnostic pop


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


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn