在使用 NSMutableArray 時,經常會對陣列中的元素做增減的動作,而在做元素刪除時,若有使用 foreach 來遍歷各個元素比對後刪減,就會發生 NSGenericException 的錯誤。
原因是只要在 foreach 裡做刪減時會將陣列的值全部失效,若剛好是最後一個值就沒問題,若不是即報錯誤。
解決方式提供2種,1種是一樣使用 foreach 做刪減,但完成後即 return 跳出。另1種是改用 for 迴圈即可。
2014年3月18日 星期二
2014年3月8日 星期六
[iOS] 如何設定系統相機、相簿的語系
每次在使用 iOS 的預設拍照時,都會遇到語系是英文,即拍照畫面上的文字為英文語系。
如:取消=cancel,重新拍攝=retake 等等。
如果要支援其他語系(依使用者裝置預設的語系),設定很簡單,只要把專案的 Localizations 裡新增想要的語系即可。
另一個是在 info.plist 裡增加 Localized resources can be mixed 為 YES
如:取消=cancel,重新拍攝=retake 等等。
如果要支援其他語系(依使用者裝置預設的語系),設定很簡單,只要把專案的 Localizations 裡新增想要的語系即可。
另一個是在 info.plist 裡增加 Localized resources can be mixed 為 YES
2014年3月3日 星期一
[iOS] 使用 AFNetworking 遇到 "Error Domain=AFNetworkingErrorDomain Code=-1016" 處理小記
常常使用 AFNetworking 在處理與伺服端的 api 溝通,而回傳值是用 Json 格式。
最近遇到伺服端回傳 text/html 的 content-types,而 AFJSONRequestOperation 預設支援的 content-types 為 "text/json", "application/json" or "text/javascript" 這三種。
解決方法為將 text/html 加入支援的 content-types 即可
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
最近遇到伺服端回傳 text/html 的 content-types,而 AFJSONRequestOperation 預設支援的 content-types 為 "text/json", "application/json" or "text/javascript" 這三種。
解決方法為將 text/html 加入支援的 content-types 即可
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];
2014年1月21日 星期二
[iOS] iOS7 在提示使用者給予 app 評分&評論小記
最近許多 app 會在內部新增一個按鈕或視窗提示使用者給予 app 好的評分 or 評論,來提升 app 的排名等等。記錄一下連結在 iOS7 的改變:
itms-apps://itunes.apple.com/app/idAPP_ID?at=10l6dK
iOS 6以下可用原本的連結:
itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APP_ID?at=10l6dK
APP_ID:可在 itunes connect 裡查看
2013年10月29日 星期二
[iOS] iOS7 使用 UIAlertView 顯示輸入框小記
在 iOS6 以前,會使用以下方法來顯示輸入框:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter Password" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setSecureTextEntry:YES]; //輸入內容為密碼
[alert addSubview:myTextField];
[myTextField release];
但在 iOS7 以後,addSubview 函式不支援了,要改統一使用以下方法:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter Password" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; //輸入內容為密碼
UITextField *myTextField = [alertView textFieldAtIndex:0];
[alertView show];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter Password" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setSecureTextEntry:YES]; //輸入內容為密碼
[alert addSubview:myTextField];
[myTextField release];
但在 iOS7 以後,addSubview 函式不支援了,要改統一使用以下方法:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter Password" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; //輸入內容為密碼
UITextField *myTextField = [alertView textFieldAtIndex:0];
[alertView show];
2013年10月16日 星期三
[iOS] 測試 InApp 時,出現無法連接 iTunes Store 的錯誤時處理小記
每次測試 InApp 總讓我有新的注意事項,發現取得付費資訊正常。
但按下確認要輸入帳號資訊時,一直出現"無法連接 iTunes Store"的錯誤訊息。
結果才發現,要先把設定裡的 apple id 登出,才可使用。
或者直接登入在 iTunes Connect 裡建立好的 tester 帳號亦可。
但按下確認要輸入帳號資訊時,一直出現"無法連接 iTunes Store"的錯誤訊息。
結果才發現,要先把設定裡的 apple id 登出,才可使用。
或者直接登入在 iTunes Connect 裡建立好的 tester 帳號亦可。
2013年10月10日 星期四
[iOS] 如何設定 SearchBar 背景色
在 iOS6 以前,加入以下方法即可。
for(UIView *subview in searchBar.subviews)
{
if([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
但在 iOS7 中,要再加下以下方式才可以。
[searchBar setBarTintColor:[UIColor clearColor]];
for(UIView *subview in searchBar.subviews)
{
if([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
但在 iOS7 中,要再加下以下方式才可以。
[searchBar setBarTintColor:[UIColor clearColor]];
訂閱:
文章 (Atom)
