1

In Apple sample code project: MoviePlayer, I want to realize that, when the sample App starts, the local video is played immediately programmatically.

I add the last 2 sentences:

[self.tabBarController setSelectedIndex:1];
[self performSelector:@selector(playMovieButtonPressed:) withObject:tabBarController.selectedViewController afterDelay:0.0];

in the function below:

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    /* Override point for customization after app. launch. */

    /* Add the tab bar controller's current view as a subview of the window. */
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible]; 
    [self.tabBarController setSelectedIndex:1];
    [self performSelector:@selector(playMovieButtonPressed:) withObject:tabBarController.selectedViewController afterDelay:0.0];
}

but get the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyLocalMovieViewController playMovieButtonPressed]: unrecognized selector sent to instance 0x6190330'

Please help, thanks!

Seki
  • 11,135
  • 7
  • 46
  • 70
user1188849
  • 107
  • 1
  • 12
  • Your code is strange because `applicationDidFinishLaunching:` method usually implemented in `AppDelegate` class, but it's look like it is called in your `MyLocalMovieViewController` class? If you call self `perfromSelector:`, than the class were you calling it, should implement method `playMovieButtonPressed:` – DanSkeel May 22 '12 at 13:15
  • Thanks Danich and Seki. I got the following error when add the previous 2 sentences to applicationDidFinishLaunching of MoviePlayerAppDelegate: "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MoviePlayerAppDelegate playMovieButtonPressed:]: unrecognized selector sent to instance 0x6285470' " . I just want to realize the effect that, when App starts, it jumps to the second tabview directly and the "play (local) Video" button on the second tabview is clicked programmatically. Please help.thanks.Please neglect my first illustration.Just focus this illustration – user1188849 May 23 '12 at 00:08
  • If you want to edit something, don't comment, better edit your question and type **edit:** at the end, and provide info for edit – DanSkeel May 23 '12 at 05:58
  • As I said your method `playMovieButtonPressed:` is implemented in your class `MyLocalMoviePlayer`. So when you try to do `[self perfor...]` you perform it on your current class `MoviePlayerAppDelegate`. – DanSkeel May 23 '12 at 06:06

1 Answers1

2

You need to get pointer to your MyLocalMovieViewController and just do something like

[pointer playMovieButtonPressed:nil]
DanSkeel
  • 3,853
  • 35
  • 54
  • Great! Thanks Danich so so much! Your method works!I set the tab bar hidden and add the following : [self playMovieButtonPressed:nil]; in the viewdidload of MyLocal... – user1188849 May 23 '12 at 08:11
  • Sorry, another question appears. I want to invoke and start this MoviePlayer from my other project. But this MoviePlayer has not xib files, just has MainWindow.Xib and SecondView.Xib files. I can't start MoviePlayer Sample code from my other project by using initWithNib. I meet the same problem before in my other question thread and still unsolved: http://stackoverflow.com/questions/10600979/how-to-add-a-ready-to-use-project-created-and-started-with-application-delegat – user1188849 May 23 '12 at 08:37
  • I commented that question. I think you should copy classes that you need and add to new project and reuse them. I think it's better way. – DanSkeel May 23 '12 at 15:40