delegateの実装

Modelクラス ViewControllerクラス

Modelクラスでデータベースに値を入れたことをViewControllerに伝える。

プロトコルの宣言 ② delegateプロパティを宣言。アクセッサ (weak, nonatomic)

FolderManager.h

#import <Foundation/Foundation.h>
#import "Folder.h"

@protocol ManagingFolderDelegate <NSObject> // ①

-(void)didFinishTransactFolder;

@end

@interface FolderManager : NSObject
@property (weak, nonatomic) id<ManagingFolderDelegate>  delegate;  // ②

 // 以下省略

③ ManagingFolderDelegateに準拠する

FolderListViewController.m

@interface FolderListViewController ()<ManagingFolderDelegate>

④ delgateするクラスのプロパティを自身に割り当てる(viewDidLoadとか)

self.folderManager.delegate = self;

ControllerからDataSourceを切り離す

  1. データソースクラスのヘッダーにUIKitインポート
#import <UIKit/UIKit.h>
  1. データソースクラスのヘッダーにUITableViewDataSource準拠の宣言
@interface TableDataProvider : NSObject<UITableViewDataSource>
  1. ViewControllerクラスでデータソースクラスのインスタンスをプロパティで保持
@property(strong, nonatomic) TableDataProvider *dataSource;
  1. ViewControllerのviewDidLoadなどに以下を記載(ViewControllerのtableviewのデータソースにTableDataProviderのインスタンスを指定)
self.dataSource = [[TableDataProvider alloc]init];
self.tableView.dataSource = self.dataSource;

以上

defaultのストーリーボードを消去して新規でストーリーボード作成する場合

ビルドしてFolderListViewControllerから表示される

  1. info.plistの書き換え f:id:ichi6161:20170621235127p:plain

  2. ViewControllerにカーソルを合わせて、storyboardのClassを変更f:id:ichi6161:20170621235137p:plain

  3. is initial ViewContollerにチェックを入れる f:id:ichi6161:20170621235141p:plain

  4. xibファイルを使用する時のapp delegateに記載するコードはいらない(入れるとViewの上にあるオブジェクトが表示されない)

storyboardを使わない場合

1. プロジェクトを作った際に作られるdefaultのファイルを消去する

Main.storyboard, ViewController.h, ViewController.mwo
Move to Trashを選択する

2. info.plistを修正

“Main storyboard file base name”の欄が"main.storyboard"となっているので、"main.storyboard"を消すか、その列にカーソルを合わせてdeleteキーを押して削除する

3. コマンド+ Nキーで新しいファイルを作成

UIViewControllerクラスを継承したクラスを作る(xibファイルを使う場合はそれにcheckを入れる)

4. AppDelegate.m ファイルに先ほど作成したViewControllerクラスのヘッサーをimport

5. AppDelegate.mファイルにコードを追加

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

  // Override point for customization after application launch
  self.window.backgroundColor = [UIColor whiteColor];

  MainViewController *viewController = [[MainViewController alloc] init];

  self.window.rootViewController = viewController;
  
  [self.window makeKeyAndVisible];
 
  return YES;
}

参考:

medium.com

Readmeテンプレート

R## 概要 歯車が回転したり、止まったすことで、タスクが進行中であることを示すクラス

継承元

UIView

実装手順

1.ストーリーボードから、UIButtonのアクションを2つとUIActivityIndicatorViewを追加
2.上記をViewControllerと紐付け
3.メソッド実装

主要プロパティ                                      

プロパティ名                                説明                                       サンプル            
hidesWhenStopped アニメーション中でない時に、indicatorを隠す       indicator.hidesWhenStopped = true |                           
isAnimating         アニメーション中か確認(Bool)                         indicator.isAnimating              
color                  indicatorに色をつける                             indicator.colar = UIColar.red      

主要メソッド

      メソッド                             説明                                     サンプル              
startAnimating()   アニメーションスタート                 indicator.startAnimating() |      
stopAnimating()   アニメーションストップ                 indicator.stopAnimating()  

フレームワーク

UIKit.framework

サポートOSバージョン

iOS2.0以上

開発環境

Category Version
Swift 3.02
XCode 8.2.1
iOS     10.0〜

参考

画像のキャッシュ(SDWebImage)

Apiで取得したurlを使って画像をキャッシュ→表示させる

①PodfileでSDWebImageをインストール ②#import <SDWebImage/UIImageView+WebCache.h> ③コーディング

1.


こんな感じにPodfileに書き込み
Pods for HotPepperApp
pod ‘AFNetworking’
pod ‘SDWebImage’


2.

#import <SDWebImage/UIImageView+WebCache.h></br>

3.

NSURL *url = [NSURL URLWithString:shop.logo];
        UIImage *placeholderImage = [UIImage imageNamed:@"noImage"];
                    [cell.logoImage sd_setImageWithURL:url
                   placeholderImage:placeholderImage];

.gitignoreの作り方

gitignoreファイルの作成

git管理下でプロジェクトを作成

atomなどのエディタで.gitignoreファイルを作成

以下をエディタに記載し、.gitディレクトリと同じ階層におく

*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcworkspace/contents.xcworkspacedata
*.swp
.DS_Store

###すでに開発を進めていて、後から追加する場合

上記の手順を踏んだ後ターミナルですでにコミットしてしまった不要なファイルを削除 

$ git rm --cached プロジェクト名.xcodeproj/project.xcworkspace/xcuserdata/ユーザー名.xcuserdatad/UserInterfaceState.xcuserstate

先ほど足した.gitignoreファイルをadd

$ git add .gitignore

忘れずにコミット

git commit -m "remove chache and add .gitignore"


以上