ios - Objective-c: How to invoke method in container view controller -
this question has answer here:
solution problem below
with iskindofclass. @julian!
-(void)callcontainerviewcontroller { (uiviewcontroller *childviewcontroller in [self childviewcontrollers]) { if ([childviewcontroller iskindofclass:[containerviewcontroller class]]) { //found container view controller containerviewcontroller *cvc = (containerviewcontroller *)childviewcontroller; //do container view viewcontroller [cvc callfunction]; break; } } }
///
my problem
i'm using storyboard. i've read child view controller of container view instantiated automatically. how call method within blueviewcontroller redviewcontroller? i've tried several solutions here, nothing worked in case.
structure currently:
entryviewcontroller.h/.m
.. view
.... other objects
.... container view
........container view rateviewcontroller.h/.m
here's setup far. need do. want understand how works:
/
entryviewcontroller.h
@interface entryviewcontroller : uiviewcontroller { } @end
/
entryviewcontroller.m
#import rateviewcontroller.h @implementation -(ibaction)callresetscrollviewmethodfromrateviewcontroller { [rateviewcontroller resetscrollview]; } @end
/
rateviewcontroller.h
@interface rateviewcontroller : uiviewcontroller { } @property (nonatomic, assign) rateviewcontroller *_rateviewcontrollerproperty; @property (nonatomic, strong) iboutlet uiscrollview *scroller; @end
/
rateviewcontroller.m
@implementation -(ibaction)resetscrollview { [_scroller setcontentoffset:cgpointzero animated:no]; } @end
you should able access viewcontroller's child through parent's childviewcontrollers
property. (or using segue pointed out above).
eg:
blueviewcontroller *bvc = self.childviewcontrollers[0]; //assuming have 1 child [bvc somemethod];
Comments
Post a Comment