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

iOS 開發百問(1)

黄舟
黄舟原創
2017-01-20 09:23:321025瀏覽

1、設定 ImagePicker 的大小
ImagePicker 在 Popover Controller 總是以預設大小顯示,設定 popoverContentSize 屬性似乎無用。解決方法是將ImagePicker 「包含」到一個客製化的 ViewController 中,然後再 presentPopover 這個 ViewController :

UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(600,self.view.frame.size.height);
[containerController.viewaddSubview:_imagePicker.view];
_popController= [[UIPopoverController alloc] initWithContentViewController:containerController];
CGPoint p=[self.view convertPoint:button.center
fromView:sender.superview];
[_popController presentPopoverFromRect:(CGRect){p,CGSizeZero}
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
[_imagePicker.view setFrame:containerController.view.frame];// 很重要

注意,popover的寬度最多600。此外,_imagePicker 每次 presentPopoverFromRect 之前都必須 init一次,否則顯示位置不正確。
2、上傳檔案中文檔案名稱亂碼問題
在iOS客戶端將檔案名稱用URL Encode編碼,然後在服務端用URL Decode解碼。
客戶端:

NSStringEncodingenc=NSUTF8StringEncoding;
[request setData:datawithFileName [filename stringByAddingPercentEscapesUsingEncoding:enc]
andContentType:@"application/octet-stream" forKey:key];

服務端:

String filename=request.getParameter(“upload_file”);
filename=URLDecode.decode(s,”utf-8”);

3、Mac 64 bit Device
有時從SVN更新工程後,Scheme會顯示為Mac 64 bit Device,且不允許執行程式。這時只需要重新設定Target的DeploymentTarget就好(設定為模擬器或偵錯設備)。
4、去除調試程式的NSLog
編譯參數Optimize Level依照不同的版本設定。例如對於Debug版本是None,對於Release版本是Fastest,Smallest。這樣,我們可以根據這個參數來重新定義NSLog函數:

#ifndef __OPTIMIZE__
#define NSLog(...)NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif

5、警告:no previous prototye for function
根據c規範, 如果函數沒有參數,使用void作為函數參數。
函數宣告應使用「void functionA(void);」,而不能是」void functionA();」.
6、陣列排序
方法一: 

- (NSComparisonResult)compare:(Person *)otherObject {
return [self.birthDatecompare:otherObject.birthDate];
}
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingSelector:@selector(compare:)];

法二: 

):



NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc]initWithKey:@"birthDate"
ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedArray;
sortedArray = [drinkDetails sortedArrayUsingDescriptors:sortDescriptors];

7、Xcode 4的build目錄在哪裡?

Xcode 4 做了許多改變。你將不能找到build目錄,你也無法找到Products檔案組。那麼它把專案編譯後產生的執行檔放在哪裡了呢?答案就是「{USERNAME}/Library/Developer/Xcode/DerivedData/{PROJECT_NAME_AND_RANDOM_CRAP}/Build/Products/{BUILD_TYPE}/{PROJECT_NAME}.app」目錄。
8、警告:no rule to process file
Xcode試圖偵測每種檔案的類型。當它認為檔案屬於「原始檔案」類型(例如.js檔案),總是試圖將它加入 Compile Sources中並試圖編譯。解決這個警告的方法是,把這類檔案從Build Phases的 Compile Sources移到 Copy Bundle Resources。
9、警告:'initWithFrame:reuseIdentifier:'is deprecated
該方法在後續版本中將被拋棄。請使用
- initWithStyle:reuseIdentifier:
10、itms-services不工作
itms-services 被apple/iphone識別為一個特殊的字眼,它會校驗provisioning profile中指定的證書並進行安裝。
在安裝這個.ipa檔案前,要校驗profisioning profile,這會連接到 "ax.init.itunes.apple.com"和 "ocsp.apple.com"。
如果你處於intranet中,請檢查是否可存取上述位址。如果不能,你將無法使用OTA來安裝應用程式。要求iOS 4.0以上。
註:上述位址不能存取並不會影響安裝。但iOS會在運行時透過上述位址檢查憑證是否合法,如果安裝是合法的,iOS會快取檢查結果(7天)。

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


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