Objective-C

NSURL, NSURLRequest, NSURLConnectionの基本

- (void)main { NSURL * url = [[NSURL alloc] initWithString:@"http://www.yahoo.co.jp"]; NSURLRequest * req = [[NSURLRequest alloc] initWithURL:url]; NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if(co…

UIImageにURLからイメージを読み込ませる

NSURLからNSDataにデータを入れてそのままUIImageに投げればいいだけです。 簡単ですが忘れがち。非同期にするにはちょっと工夫がいりますね。ここでは実装してません。 UIImageView * imageView = [[UIImageView alloc]init]; NSURL *url = [NSURL URLWithS…

touchesBeganなどUIResponderのメソッドをdelegateする

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded: (NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesCancelled:(NSSet *)touch…

NSTimerとuserInfoの使い方。

よく使うのにたまに忘れがちなのでNSTimerの使い方かきました。userInfoの使い方とか参考になれば。 http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html#//apple_ref/doc/uid…

iOS(iPhone/iPad)アプリケーション公開申請までの流れ(Xcode4)

iOS(iPhone/iPad)アプリケーション公開申請までの流れをなるべく分かりやすく確認できるように工夫して書きました。application1.xcodeprojというプロジェクトで開発を進めたということで話を進めています。プロジェクト名が違う場合は置き換えてください。 …

AVAudioPlayerでfadein/fadeout(フェードイン・フェードアウト)を実装したライブラリ

AVAudioPlayerを使ったライブラリを作りました。AVAudioPlayerの実例が少なかったからしっかりとまとめた。AudioQueueとかAudioUnitじゃないとできないんじゃないの?ということがAVAudioPlayerでできます。 AudioPlayerDelegateをdelegateして使いたいクラ…

AVAudioPlayerを使った音楽ファイルの再生

AVAudioPlayerを使って音楽を再生する方法です。再生時間をNSTimerを使って表示しています。NSRunLoopでも表示は可能かと思いますがNSTimerのほうがはるかに楽です。githubにもございます。 GitHub - kmusiclife/AudioPlayer: This is AudioPlayer class ext…

NSArray, NSMutableArrayをランダムに置き換える

- (NSMutableArray *)randomizedArray:(NSMutableArray *)filename{ srand([[NSDate date] timeIntervalSinceReferenceDate]); int i = [filenames count]; while(--i) { int j = rand() % (i+1); [filenames exchangeObjectAtIndex:i withObjectAtIndex:j];…

UIViewでよく使うのに覚えきれないメモ

UIViewContentMode typedef enum { UIViewContentModeScaleToFill, // これがデフォルト。UIImageViewにめいっぱいひろげる UIViewContentModeScaleAspectFit, // 画像のaspect比を維持し、ちょうどはいるようにする UIViewContentModeScaleAspectFill, // …

UIViewでUITouchを使って右フリック・左フリック・上フリック・下フリックを検出する

UIViewControllerを利用した上で右フリック・左フリック・上フリック・下フリックを検出する方法です。UIViewControllerのdelegateで実装される -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -(void)touchesEnded:(NSSet *)touches wit…

UITabBarNavigationにUINavigationController+UITableViewControllerとUIViewControllerを同時に使う

長いタイトルですがタイトルの通りです。UITabBarNavigationにUINavigationController+UITableViewControllerとUIViewControllerを同時に使う。意外とややこしかったのでテンプレでまとめておきました。結構使うのにサンプルが少なかったりします。結局こう…

Objective-CでのTips UITableViewControllerのimplements

UITableViewControllerのimplementsを忘れるのでメモついでに。 #import "MyClass.h" @implementation MyClass @synthesize items; // 独自の拡張メソッド -(id) initWithTableObject:(UITableViewController *)tableView{ items = [[NSMutableArray alloc]i…

Objective-CのTips tableViewを動的に追加する

tableViewに動的に一行を追加する おもった以上に迷いました。 /* NSMutableArray * items; @property (nonatomic, retain) NSMutableArray * items; @synthesize items; */ [self.tableView beginUpdates]; [items addObject:@"ADD CEL"]; NSIndexPath * pa…

Objective-CでのTips UIControllerなど

UINavigationControllerに関する忘れがちなメモ // UITableViewのCellをクリックしたときの動作 detailViewController * detail = [[detailViewController alloc]initWithNibName:@"detailViewController" bundle:nil]; // extends UITableView [self.naviga…