AppDelegateインスタンスを外から参照する

xxxAppDelegate *appDelegate = (xxxAppDelegate *)[[UIApplication sharedApplication] delegate]; これで簡単に参照取れました。

BSTimeIntervalをNSStringに変換

Matthias Bauch氏の投稿より。 - (NSString *)stringFromTimeInterval:(NSTimeInterval)interval { NSInteger ti = (NSInteger)interval; NSInteger seconds = ti % 60; NSInteger minutes = (ti / 60) % 60; NSInteger hours = (ti / 3600); return [NSStri…

NSLogをDebug時のみ出力するようにする

http://d.hatena.ne.jp/k2_k_hei/20120511/1336750473 こちらを参考にしました。

iPhoneキーボードの外をタップしてキーボードを閉じる方法

http://qiita.com/yuch_i/items/65baa9586afdfc6aeb34 参考になります。 複数のTextFieldがある場合にはどうしようか。 ベタに書くのもありだけれど。

UITableViewCell内のrecognizerタップイベントからタップ位置を計算する

recognizerで呼ばれるメソッドにて。 CGPoint p = [recognizer locationInView:self.mainTableView]; CGPoint offset = self.tableView.contentOffset; float pos_y = p.y - offset.y;

UITableViewのロード完了時に処理するには

http://stackoverflow.com/questions/1483581/get-notified-when-uitableview-has-finished-asking-for-data まだ未実験だが上記の情報でできそうだ。

設定値のキーと値をすべて見る方法

[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]; デバッグ時はコンソールにて po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]

処理の遅延実行

[self performSelector:@selector(methodA:) withObject:nil afterDelay:0.1]; メソッドに引数を渡す場合はwithObjectに設定。

iOSアプリをコードから強制終了 するけれど...

exit(0); で、終了します。 しかしAppStoreのガイドライン違反なのでリジェクトされるようです。 企業向けアプリや実験時に。

UITableViewCell選択時に色を変えない

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath にて [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

任意の文字をTrimする

NSString *str = [NSStringFromSelector(originalStr) stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@":"]]; この場合は「:」をTrimしている。

実行中のメソッド名の取得と文字列で指定してのメソッド呼び出し

objective-c。 ■実行中のメソッド名の取得 NSStringFromSelector(_cmd)) ■文字列で指定してのメソッド呼び出し [self performSelector:NSSelectorFromString(@"methodA")];

UIViewの外側に枠線を付ける

import <QuartzCore/QuartzCore.h> [[uiview layer] setBorderColor:[[UIColor whiteColor] CGColor]]; [[uiview layer] setBorderWidth:1.0];</quartzcore/quartzcore.h>

UITableViewの罫線非表示

tableView.separatorColor = [UIColor clearColor]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; スタイルのみの指定で良さそうですが、Groupタイプのテーブルでは表示されてしまうようです。

UILabelの外側に枠線を付加

label.layer.borderColor = [UIColor blackColor].CGColor; label.layer.borderWidth = 1.0;

グレートタイムライン

グレートタイムライン構想。 宇宙の始まりから、現在、未来までの出来事を一つのタイムラインに集約した、すべてのタイムライン。 イメージは「タイムライン版のWikipedia」 「中国三国志の時代、日本は卑弥呼の邪馬台国だった」 「イギリスで産業革命が始ま…

UITextFieldの自動補完を切る方法

textField.autocapitalizationType = UITextAutocapitalizationTypeNone; textField.autocorrectionType = UITextAutocorrectionTypeNo; 勝手に変更されるのをやめたかった! そしてWordの世話焼きな自動変換を思い出した。

init呼び出し禁止(ビルドエラーにさせる)

- (id)init __attribute__((unavailable("init is not available"))); これを.hの方に記述。

MSMutableString 末尾1文字削除

[sql deleteCharactersInRange:NSMakeRange([sql length] - 1, 1)];

スクロールバー点滅

スクロールバー点滅 [scrollView flashScrollIndicators];

NSArrayの要素が文字列の場合に数値としてソートする場合

http://ssdkfk.wordpress.com/2011/07/25/nsarrayにnsdictionaryを入れている時のソートはどうする?/ NSSortDescriptor *descriptor=[[[NSSortDescriptor alloc] initWithKey:@"number.intValue" ascending:YES] autorelease]; NSLog(@"Sorted :::: %@",[[d…

SQL Server からの返答が遅い場合の対応策

インデックスの再作成により改善する可能性がある。 以下のページの手順に従い、インデックスを再構成。 インデックスを再構築する方法 (SQL Server Management Studio) http://technet.microsoft.com/ja-jp/library/ms187874(v=sql.105).aspx

iOS データ保護(Data Protection)

http://cocoadays.blogspot.jp/2011/04/ios-data-protection.html データ保護。

ios7でundeclared selector警告が出る場合の対応

SEL setErrorSelector = sel_registerName("setError:"); if([self respondsToSelector:setErrorSelector]) { [self performSelector:setErrorSelector withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]]; } 一度SELに登録し使用す…

メソッドの遅延実行

http://www.objectivec-iphone.com/foundation/Class/performeSelector.html 画面表示時にローディング画面を表示し、その後時間の掛かる処理をする場合。

他のアプリ起動

NSString * retURL = [NSString stringWithFormat:@"xxxxx://xxxxx?param=1"]; NSURL* url = [NSURL URLWithString:retURL]; UIApplication* app = [UIApplication sharedApplication]; if ([app canOpenURL:url]) [app openURL:url];

iOS ローカルファイル上書き

http://www.deftrash.com/blog/archives/2010/10/iphone_file_append.html を参考。 一度削除して再配置。

iOS7 StatusBarの文字色を白色に変更

http://tryworks-design.com/?p=2333 を参考にした。

SQL Server で同じインスタンスにDBをコピー

http://blacky-obrien.blogspot.jp/2012/10/sql-server.html を参考にした。 注意点は、バックアップ作成の際に バックアップコンポーネントでファイル及びファイルグループ を選択すること。

iOS App IDが消せるようになっている!

今日、Dev Centerを確認してみたらデザインが変更されていて なんとAppIDが消せるようになっていた! いやー、これは嬉しい。 消せると消せないでは心理的負担が大違いだな。 自分でサービス作る時も押さえておこう。 「これにならお金を払う」 「なぜ無いの…