ios - UIView not displaying on storyboard -


i've created uiview(kgcalloutview) , placed in storyboard(main.storyboard)by dragging on view object , setting class kgcalloutview. when run project view never displayed in storyboard.

my first attempt resolve entailed adding following method, resulted in believe infinite loop(understandably) , crashed.

- (void)awakefromnib {     if ([[nsbundle mainbundle] loadnibnamed:@"kgcalloutview" owner:self options:nil]) {         [self.view setframe:[self bounds]];         [self addsubview:self.view];     } } 

next tried adding init method below, did not resolve issue either:

- (id)initwithcoder:(nscoder *)adecoder {     if ((self = [super initwithcoder:adecoder])) {     }      return self; } 

i tried post images of .xib , main.storyboard guess reputation isn't high enough yet.

here kgcalloutview.h:

@interface kgcalloutview : uiview <uipickerviewdatasource, uipickerviewdelegate>  @property (nonatomic) ibinspectable nsstring *title; @property (strong, nonatomic) iboutlet kgcalloutview *view;  @property (weak, nonatomic) iboutlet uitextfield *titlefield; @property (weak, nonatomic) iboutlet uipickerview *typepickerview;  @end 

here kgcalloutview.m:

- (id)initwithcoder:(nscoder *)adecoder {     if ((self = [super initwithcoder:adecoder])) {     }     return self; }  - (void)awakefromnib {     if ([[nsbundle mainbundle] loadnibnamed:@"kgcalloutview" owner:self options:nil]) {         [self.view setframe:[self bounds]];         [self addsubview:self.view];     } }  -(void)layoutsubviews{     self.titlefield.text = @"test";     self.typepickerview.datasource = self;     self.typepickerview.delegate = self; } 

here's viewcontroller.h:

@interface viewcontroller : uiviewcontroller  @property (weak, nonatomic) iboutlet kgcalloutview *callout;  @end 

here's viewcontroller.m:

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

you need load view in viewcontroller able see it.

first, make sure set view's file's owner class viewcontroller (looks have done this)

file owner

second, connect view property of viewcontroller (callout)

third, instead of implementing in kgcalloutview.m, following code in viewcontroller.m

- (void)viewdidload {     [super viewdidload];      if ([[nsbundle mainbundle] loadnibnamed:@"kgcalloutview" owner:self options:nil]) { //this load view storyboard iboutlet callout         [self.callout setframe:[self.view bounds]];         [self.view addsubview:self.callout];     } } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -