ios - Instantiate view with XIB -
i have xib created next guide (how create custom ios view class , instantiate multiple copies of (in ib)?) have question:
how can instantiate if code?
so should write in viewdidload instead of
self.myview = [[myview alloc] initwithframe:self.view.bounds];
i know how instantiate storyboard, have no thought how code. thanks!
you have add together -loadnibnamed
method following:
add next code your_view init
method:
nsarray *subviewarray = [[nsbundle mainbundle] loadnibnamed:@"your_nib_name" owner:self options:nil]; uiview *mainview = [subviewarray objectatindex:0]; [self addsubview:mainview];
refer these 2 questions here:
adding custom subview (created in xib) view controller's view - doing wrong
ios: custom view xib
edit:
in viewcontroller.m
file
#import customview.h <--- //import your_customview.h file - (void)viewdidload { [super viewdidload]; customview *customview = [[customview alloc]init]; [self.view addsubview:customview]; }
ios objective-c
No comments:
Post a Comment