xcode - Calling method from another class doesn't execute the whole method -


in osx-application have main class , second class b. both run window each, @ same time.

in class there button plays movie in avplayerview (called playerview) [the movie loaded playerview earlier!]:

- (ibaction)runmovien:(id)sender {      [playerview.player play];  } 

this works fine. movie played after clicking button.

on other hand, in class b there button calls method in class a...

- (ibaction)runmovie:(id)sender {      viewcontroller *runmoviebutton = [[viewcontroller alloc] init];     [runmoviebutton runmovie];  } 

...which run method in class a:

- (void)playpause {      nslog(@"a");     [playerview.player play];  } 

the problem is, log printed out fine, else in method ignored, no matter in there. content of bracket being ignored completely, except log.

the solution easy, cannot come possibly work.

in mainviewcontroller.h

@interface mainviewcontroller : uiviewcontroller -(void)playmedia:(nsurl*)url; @end 

in mainviewcontroller.m

@interface mainviewcontroller () @property(nonatomic, retain) avplayerlayer *layer; @property(nonatomic, retain)  avplayer *player; @end  @implementation mainviewcontroller  -(void)playmedia:(nsurl*)url{      self.player = [avplayer playerwithurl:url];     self.layer = [avplayerlayer playerlayerwithplayer:self.player];     self.player.actionatitemend = avplayeractionatitemendnone;     self.layer.frame = cgrectmake(0, 0, 200, 200);     [self.view.layer addsublayer: self.layer];      [self.player play]; }  -(ibaction)playbutton:(id)sender {     [self playmedia:[nsurl urlwithstring:@"http://content.jwplatform.com/manifests/vm7nh0kl.m3u8"]]; }  -(ibaction)movetochild:(id)sender {     [self.layer.player pause];     [self.layer removefromsuperlayer];     self.player=nil;      childviewcontroller* childview = [[childviewcontroller alloc] initwithnibname:@"childviewcontroller" bundle:nil];     [self presentviewcontroller:childview animated:yes completion:nil]; }  @end 

in childviewcontroller.h

@interface childviewcontroller : mainviewcontroller  @end 

in childviewcontroller.m

  -(ibaction)playbutton:(id)sender{     [self playmedia:[nsurl urlwithstring:@"http://srv6.zoeweb.tv:1935/z330-live/stream/playlist.m3u8"]]; } 

please not if no parent child relation in 2 classes can use delegates interact between viewcontrollers


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -