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

iOS 開發百問(3)

黄舟
黄舟原創
2017-01-20 09:27:251131瀏覽

22、解決messagesent to deallocated instance 0x52cc690 錯誤
當試圖對某個物件進行賦值操作的時候出現這個錯誤,如:
tfContent.text=bodyText;
此時,你可以開啟NSZombieEnable,tfconsole.輸出:
***-[CFString _isNaturallyRTL]: message sent to deallocated instance 0x52cc690 
說明_isNaturallyRTL訊息被傳送給了一個已經釋放了的物件。從上面的語句看,可能是這兩個物件:tfContent、bodyText。
你可以列印tfContent或bodyText的記憶體位址,看看到底是哪個物件已經被釋放掉了:

NSLog(@"tfContent:0x%x",(int) tfContent);
NSLog(@"bodytext:0x%x",(int) bodyText);

結果表明是bodyText被提前釋放:

tfContent: 0x52cf160
bodytext: 0x52cc690

在適當的地方對bodyText進行retain,問題解決。
23、 putpkt:write failed: Broken pipe錯誤
重啟裝置。
24、.hfile not found
其實該.h檔並沒有被包含進target。選擇對應.m文件,點選「ShowUtilities」按鈕(在工具列的右端),在Utilities中找到Target Membership,將Target前面的勾去掉,然後再重新勾上。即相當於將該.m檔重新加入target的Buildphase。
25、 Xcode 4:如何將for iPhone的xib轉變為for iPad
在Xcode 3.x中,將xib從iPhone版轉變為iPad版,透過Create iPad Version選單。
但在Xcode 4.x中,這個選單找不到了。透過一番摸索,筆者發現可以用以下方法將xib轉換為iPad版本。
1、修改xib原始檔
xib檔其實是一個xml檔。在Project Navigator中,在xib文件上右鍵,選擇“Open As -> Source Code”,即可以原始碼方式查看xib文件,找到"com.apple.InterfaceBuilder3.CocoaTouch.XIB"一行,將其改為"com .apple.InterfaceBuilder3.CocoaTouch.iPad.XIB",即增加了".iPad"。
按下⌘+F,開啟搜尋欄,點選Replace選單,將模式改變取代模式。將xib檔案中所有"IBCocoaTouchFramework"用 "IBIPadFramework"取代。
按⌘+S,儲存修改。
2、修改xib的視圖尺寸
在xib檔案上右鍵,選擇“Open As -> Interface Builder – iOS”,用IB模式開啟。
選擇xib檔案中的根視圖(UIView),在屬性面板中找到Size選項,將其改為Full iPad Screen。

現在,你可以有一個iPad版本的xib了。

26、icon dimensions (0 x 0) don't meet the size requirements.
開啟Project的BuildSettings,找到Compress PNG Files,將數值設為No。
或:
選取該png文件,在FileInspector面板中,找到File Type,將其由"PNG" 修改為"Icon".
27、警告: noprevious prototype for function
開啟Target->BuildSettings,搜尋prototype,將Missing Function ProtoTypes改為NO。
28、CorePlot編譯時出現 錯誤「Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clangfailed with exit code 1」
請將Scheme 從 iOS Device 改為 iPhone 5.0 Simulator。或將Compiler for C/C++ 改為 LLVM GCC4.2。同時,Core Plot 1.0 不再支援舊的 armv6 CPU。
29、使用CABasicAnimation改變UIView的alpha值無效
UIView的alpha值,在CALayer中其實是"opacity",請使用opcity作為keyPath。
30、CorePlost:定制 Axis Label 後,Tick Mark 不顯示。
設定Axis 的majorTickLocations 為你想顯示 tick mark 的位置。

NSMutableArray*customTickLocations=[[[NSMutableArray alloc]init]autorelease]; 
for(int i=0;i<10;i++){
[customTickLocationsaddObject:[NSNumber numberWithInt:i]];
}
xAxis.majorTickLocations=[NSSetsetWithArray:customTickLocations];

31、客製化的UITableViewCell, indentationLevel無法生效
需要在客製化的UITableViewCell中實作layoutSubviews方法。

- (void)layoutSubviews
{
[super layoutSubviews];
float indentPoints = self.indentationLevel *self.indentationWidth;
for(UIView *view in self.subviews){
view.frame = CGRectMake(
view.frame.origin.x+indentPoints,
view.frame.origin.y,
view.frame.size.width, 
view.frame.size.height
); 
}
}

以上就是iOS 開發百問(3)的內容,更多相關內容請關注PHP中文網(www.php.cn)!


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