[英]running a project created in xcode 4.2(deployment target 5.0) in xcode 4.0 (deployment target 4.0)
[英]iPhone build which supports version 4.0 to 5.0 using Xcode 4.2
嗨,我正在使用xcode 4.2開發iOS SDK5,我想准備一個應該與iOS 4.0至5.0或至少與4.3和5.0兼容的版本
我已將基本sdk設置為5.0,將部署目標設置為4.0,但是當我在iPhone 4模擬器中運行該應用程序時,由於以下代碼,我的應用程序崩潰
[testNavigationBar setBackgroundImage:[UIImage imageNamed:@"facebook-navbar.png"] forBarMetrics:UIBarMetricsDefault];
但是當我將iPhone模擬器從4切換到5時,上面的代碼運行良好,我也嘗試過setBackgroundColor,但是它不能正常工作,請幫忙。
問題在於該方法已添加到iOS5,因此在iOS4中不存在。 您需要進行運行時檢查,看看您是否在iOS5中,如下所示:
if ([testNavigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics)]) {
[testNavigationBar setBackgroundImage:[UIImage imageNamed:@"facebook-navbar.png"] forBarMetrics:UIBarMetricsDefault];
}
現在的問題是,您不會在iOS4中獲得背景,因此您必須找到一種解決方法。
這是因為-setBackgroundImage:是iOS 5中引入的,而Apple通常不會(通常)將新API移植回舊平台。 無論如何,您有兩個選擇:
if ([testNavigationBar respondsToSelector:@selector(setBackgroundImage:)]) {
// do what you're currently trying
}
else {
//find a compatible way to do it
}
要么:
//find a compatible way to do it
對於iOS版本4.x,您始終可以覆蓋UINavigationBar drawRect。 這是有關此主題的Stack Overflow上的帖子:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.