2014-09-01から1ヶ月間の記事一覧

Coredataとは

iOSのアプリ固有領域にデータを永続化する主な方法は以下の通りです。 オブジェクトアーカイブ オブジェクトをバイナリ形式に変換してからファイルに永続化する。一般的にはオブジェクトシリアライズと呼ばれる。使用頻度は少ないが SDK の中で頻繁に使われ…

Coredataの作り方基礎

xcodeを立ち上げます プロジェクトを作成します。 targetsのプロジェクト名をクリックして「Linked Frameworks and Libraries」をから「CoreData.framework」を追加します。 fileの作成から「Data Model」の作成を行います。 「Model.xcdatamodel」が作成さ…

magicalrecordの設定

coredataでDBを作成cocoapodsで「MagicalRecord」をインストール hogehoge-Prefix.pchを開いて次の1行を追記します。 #import <Availability.h> #ifndef __IPHONE_5_0 #warning "This project uses features only available in iOS SDK 5.0 and later." #endif #ifdef __OBJC</availability.h>…

UIDatePickerを使う

ストーリーボードから、ひも付けを行う場合。connectionは、outletとaction(Event=Value Changed)を紐づけておく //outlet @property (weak, nonatomic) IBOutlet UIDatePicker *MyDateTimePicker; //action - (IBAction)MyDateTimePicker:(UIDatePicker *)s…

deallocは、必要

[iPhone] UIViewController の dealloc と viewDidUnload - それはBooks [iPhone] UIViewController の dealloc と viewDidUnload - それはBooks

テーブルの中身を変えるサンプル

self.articles = nil;//一旦初期化 //coredataからデータを取得 NSArray *result = [BookMark MR_findAll]; //NSMutableArrayを宣言 NSMutableArray *t = [NSMutableArray array]; int i;i = 0; for (BookMark *p in result) { NSDictionary *article = @{TI…

UIRefreshControlを追加した

//設置 _refreshControl = [[UIRefreshControl alloc] init]; [_refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; //tableviewに追加 [self.tableView addSubview:_refreshControl];- (void)refresh…

iAdをコードで追加

//宣言、デリゲート #import <iAd/iAd.h> @interface ViewController : UIViewController<ADBannerViewDelegate> viewDidLoadに下記を追加 adView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner]; // 画面(ビュー)の下に表示する場合 adView.frame = CGRectMake(0, self.view.frame.</adbannerviewdelegate></iad/iad.h>…

セグメントコントロールを設置

NSArray *segmentTextContext = [NSArray arrayWithObjects:@"まめ速",@"キニ速",@"お気に入り",nil]; UISegmentedControl *customSegment = [[UISegmentedControl alloc] initWithItems:segmentTextContext]; customSegment.frame = CGRectMake(40, 70, 240…

iOS7で動的にステータスバーを消すとviewが移動してしまう

まさにこれiPhone - iOS7で動的にステータスバーを消すとviewが移動してしまう - Qiita iPhone - iOS7で動的にステータスバーを消すとviewが移動してしまう - Qiita self.automaticallyAdjustsScrollViewInsets = NO;

navigationControllerのnavigationBarのtitleの色を変える

//ナビバーの色を変更 self.navigationController.navigationBar.barTintColor= [UIColor blueColor]; //タイトルの文字の色を変更 self.navigationController.navigationBar.titleTextAttributes= @{NSForegroundColorAttributeName: [UIColor whiteColor]};

文字列の定義、定数

NSString* const strHoge = @"ほげほげ";

NSDictionaryにnilを入れない為の防止策

NSDictionaryにnilを入れようとすると怒られます。 なので下記のように回避できたので備忘録的に書き残しておきます。 static id ObjectOrNull(id object) { return object ?: [NSNull null]; }NSDictionary *article = @{TITLE : ObjectOrNull(p.title), LI…

tagを使ってカスタムセルにボランを追加、削除

xibでカスタムセルを作成後、ボタンを配置します。 そのボタンのviewtagのnumberを適当な数字に指定します。 (ここでは 7 を指定) 宣言 UIButton *btn_bookmark;@property (nonatomic, retain) UIButton *btn_bookmark;@synthesize btn_bookmark; 実際にcell…

uitableviewのcellでdeleteボタンを出し分け

uitableviewのcellをスワイプすると「delete」ボタンが出るアプリがあるけど、ページによって出したり出さなかったりを変えたいのでそのサンプル //まずはDeleteボタンを表示できるようにする - (void)tableView:(UITableView *)tableView commitEditingStyl…

最後の文字を判定する

ラストの文字列が何かで判断をする。 NSString *path = @"hogehoge.jpg"; if (![path hasSuffix:@".jpg"] && ![path hasSuffix:@".jpeg"] && !path hasSuffix:@".png"] && !path hasSuffix:@".gif"]) { //ここに処理を書く }