Red > Green > Refactor > Red

cycle is based on desire

subview on main view(another view) by addSubView

非参考のお願い ... 内容不正確のため

非参考のお願い ... 内容不正確のため

非参考のお願い ... 内容不正確のため

subview on main view

will do

f:id:mat5ukawa:20150503015305p:plain

Set components on Main.storyboard as you want

f:id:mat5ukawa:20150503015936p:plain

Main.storyboard respond to TopViewController(.m | .h)

Create SubViewController Files

In this article

SampleCustomViewController(.m | .h | .xib)

will be created.

create from new File

f:id:mat5ukawa:20150503015400p:plain

  • focus on group you want to create module
  • click ‘File …’

select module

f:id:mat5ukawa:20150503015450p:plain

iOS > Source > Cocoa Touch Class

input items

f:id:mat5ukawa:20150503015414p:plain

  • input class name (in this, SampleCustomViewController)
  • SubClass is UIViewController
  • check … Also create XIB file
  • device is iPad
  • Language is Objective-C

Code

SampleCustomViewController.h

#import <UIKit/UIKit.h>

@interface SampleCustomViewController : UIViewController

// creates view instance
+(instancetype) create;

@end

SampleCustomViewController.m

#import "SampleCustomViewController.h"

@interface SampleCustomViewController ()
@end

@implementation SampleCustomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

+ (instancetype) create {
  UINib *nib = [UINib nibWithNibName:@"SampleCustomViewController" bundle:nil];
  SampleCustomViewController *viewController = [nib instantiateWithOwner:self options:nil][0];
  return viewController;
}

@end

TopViewController.h

#import <UIKit/UIKit.h>

@interface TopViewController : UIViewController

@end

TopViewController.m

#import "TopViewController.h"
// import subview SampleCustomView
#import "SampleCustomViewController.h"

@interface TopViewController ()
@end

@implementation TopViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  [self init];
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
}

- (instancetype) init {
  self = [super init];
  if(self) {
    SampleCustomViewController *sampleCustom = [SampleCustomViewController create];
    // addSubView
    [self.view addSubview:sampleCustom];
  }

  return self;
}


@end

If you’re stacked to error like below…

NSUnknownKeyException

setValue:forUndefinedKey: this class is not key value coding-compliant for the key view.
  • open subview’s xib
  • click File’s Owner
  • check CustomClass > Class … is not Empty
    • if empty, fill the respond class(in this article, SampleCustomViewController)

f:id:mat5ukawa:20150503020226p:plain

Referred to

[iPhone] this class is not key value coding-com... | Apple Support Communities

qiita.com