1

I have a ready-to-use project ( created and started with application delegate but without xib,nib). Now I want to invoke and start it from another project. But I can't use initwithnib, how can I include and start this ready-to-use project from another project? More specifically, how to add and integrate Apple's Sample code " TableViewUpdates ( TVAnimationsGestures.xcodeproject ) " which only has its own appDelegate and Mainwindow.xib file to my own application? thanks! Or can you add a xib file to the Apple's Sample code " TableViewUpdates ( TVAnimationsGestures.xcodeproject ) " so that I may use initWithNib in my another project to invoke and run the sample code. thanks !

user1188849
  • 107
  • 1
  • 12
  • I think it's not the way it should be done. You should copy your classes to new project and connect them appropriately. – DanSkeel May 23 '12 at 15:37
  • Thanks Danich for your prompt reply. I followed your advice and add the "TableViewUpdates" sample project to my existing project successfully. But when I want to integrate the MoviePlayer sample project to my another project which is based on TTNavigatorDemo of three20, it's hard to invoke it without using initNib. – user1188849 May 26 '12 at 07:43
  • Because one is Three20 project, but the other to be integrated is not based on Three20. Appreciate your further advice. – user1188849 May 26 '12 at 07:50
  • because the Apple MoviePlayer sample project is built with App delegate, instead of on a Xib. Many Apple sample code seems to be built this way. To solve this, I created a empty view based App with Xib. then integrate the Apple MoviePlayer sample code to it. ( mainly migrate the code in its App delegate file to my Xib based project.) Then this Xib MoviePlayer project worked. But if I integrate it to my other project with initNib, it has problems to work.If the Apple MoviePlayer sample project is provided with its Xib in born, then I think should be no problem to be invoked. thanks! – user1188849 May 27 '12 at 07:48
  • sorry, what I mean is that, the Apple MoviePlayer sample project just has Mainwindow Xib, does not have MoviePlayer.Xib, this is why I can't use initNib to invoke it to my project. – user1188849 May 27 '12 at 12:43
  • link as follows, thanks! http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html – user1188849 May 27 '12 at 13:31
  • Do you use storyboard? I didn't have much experience with xib, nib, but can't you just add IBOutlets to your New appDelegate class, and connect them to the window and `tabBarController`? Same way as it made in Sample? may be you have your own new Windos, or view, so you will need only that `tabBarController`? – DanSkeel May 27 '12 at 14:40

1 Answers1

2

I work on Xcode 4.3.2.

  1. Create sigle view sigle view app.
  2. Expand all folders in MoviePlayer example. Select all files, except info.plist, main, Frameworks, Products folders, readme.txt, MoviePlayer.project. Copy them to new empty project. Don't forget to check "add to target".
  3. In target's build phase tab added MediaPlayer.framework (in link Binary with libs)
  4. Copy all object from MainWindow.xib to your own xib for your viewController.

Than in ViewController.h :

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITabBarController *tabBarConroller;

@end

Connect your tabBarController from ViewController.xib to the property.

Than in ViewController.m :

@implementation ViewController
@synthesize tabBarConroller;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:tabBarConroller.view];
}

- (void)viewDidUnload
{
    [self setTabBarConroller:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}
...other appdelegateMethods ...
@end

7. Check that all objects in viewController.xib has necessary outlets.
6. Edit > Refactor > Convert to ARC. (next, ok...)

It's done.

DanSkeel
  • 3,853
  • 35
  • 54
  • Great!Thanks so much for your detail description! It works.But there are still 2 places need to be perfect. One is that,because I invoke it from a navigation App. So when I click the "Back " navigation bar,the Video still keeping running ( I changed the original Video to a video with Audio sounds).I have to do something further to stop the Video before leave the Demo by clicking the " Back" navigation bar.Another problem is that, there are 2 grey bars above and below the video screen,even if I turn it fullscreen.The lower grey bar covers half of Play bar.So only the upper half play bar appears – user1188849 May 28 '12 at 09:37
  • Post a picture. You can stop video for example in this method: [viewWillDisappear:](http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW46) – DanSkeel May 28 '12 at 11:09
  • I tried to add the following 3 line codes to the viewWillDisappear of MyMovieViewController.m, MyLocalMovieViewController.m, and MoviePlayerNibViewController.m respectively, but none of them stopped playing video when "back" item bar is clicked and the window is navigated back: [[self moviePlayerController] stop]; int i = 111222; NSLog(@"%d", i); Even none of the NSLog shows the variant i. thanks! – user1188849 May 28 '12 at 14:41
  • If you put your ViewController in NavigationController, than you should put method `viewWillDisappear:`, in that ViewController. It's called only on the controller that is in NavigationController stack. – DanSkeel May 28 '12 at 15:21
  • thank Danich for your prompt reply.I have put it before.Actually MoviePlayerNibViewController.m is the ViewController you mentioned above.It's the ViewController in your sample code above.But still viewWillDisappear in ViewController(MoviePlayerNibViewController.m) can't be called.I found some similar discussions like this:http://stackoverflow.com/questions/4289617/why-isnt-viewwilldisappear-or-viewdidappear-being-called But it still can't work in my case.Another similar post: http://stackoverflow.com/questions/1520259/viewdidappear-and-viewwilldisappear-not-being-called-in-uiviewcontroller – user1188849 May 29 '12 at 00:13
  • Explain how do you add your `MoviePlayerNibViewController` in `NavigationController`? And btw, Nib is unnecessary in your name. `MoviePlayerViewController` is better. – DanSkeel May 29 '12 at 06:54
  • myListController (NavigationController) is a Three20 class inherited from TTTableViewController. - (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query { if (self = [super init]) { self.tableViewStyle = UITableViewStylePlain;self.title = @"News"; self.variableHeightRows = YES; TTTableImageItem *item = [TTTableImageItem itemWithText:@"NEWS" imageURL:@"bundle://vedio.png" URL:@"tt://nib/MoviePlayerNibViewController"]; item.imageStyle = [TTImageStyle styleWithImage:nil defaultImage:nil contentMode:UIViewContentModeScaleAspectFill size:CGSizeMake(225.f, 215.2f) next:nil]; – user1188849 May 29 '12 at 07:26
  • You miss understanding. `NavigationController` is a subclass of `ViewController`. You can't inherit `NavigationController` from tableViewController. If you want to make your own `NavigationController` you need to subclass `UINavigationController` or [three20](http://api.three20.info/interface_t_t_base_navigation_controller.php). Read this [guide](https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerPGforiOSLegacy/NavigationControllers/NavigationControllers.html). I think you should learn more, before doing such complicated things. – DanSkeel May 29 '12 at 08:04
  • Sorry,myListController.h as follows: "#import @ interface myListController : TTTableViewController { } @end" myListController.m as follows: "#import "myListController.h" @implementation myListController -(id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query { if (self = [super init]) { self.tableViewStyle = UITableViewStylePlain;self.title =...; TTTableImageItem *item = [TTTableImageItem itemWithText:.. imageURL:@"bundle://video.png" URL:@"tt://nib/MoviePlayerNibViewController"];item.imageStyle = [TTImageStyle styleWithImage:nil defaultImage:nil contentMode:.." – user1188849 May 29 '12 at 08:58
  • My whole project is based on one of Three20 samples: TTNavigatorDemo.Following are some code in TabBarController.m :***#import "TabBarController.h"@implementation TabBarController -(void)viewDidLoad { [self setTabURLs:[NSArray arrayWithObjects:@"tt://menu/1", @"tt://menu/2", @"tt://nib/MapViewController",nil]]; [super viewDidLoad];NSArray *tabs =[self viewControllers]; UIViewController *home =[tabs objectAtIndex:0];home.tabBarItem.image =[UIImage imageNamed:@"tab.png"]; home.tabBarItem.title =@"Home";... UIViewController *map = [tabs objectAtIndex:2];}@end*** – user1188849 May 29 '12 at 12:57
  • Then in MenuController.m:***-(void)setPage:(MenuPage)page { _page = page; self.title = [self nameForMenuPage:page]; UIImage* image = [UIImage imageNamed:@"tab.png"]; self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:self.title image:image tag:0] autorelease];if(_page == MenuPageHome) { self.variableHeightRows=YES; TTTableImageItem *item = [TTTableImageItem itemWithText:@"NEWS" imageURL:@"bundle://t1.png" URL:@"tt://myList"]; item.imageStyle = [TTImageStyle styleWithImage:nil defaultImage:nil contentMode:UIViewContentModeScaleAspectFill size:CGSizeMake(150.f, 153.2f) next:nil];*** – user1188849 May 29 '12 at 13:09
  • Then in AppDelegate.m: ***- (void)applicationDidFinishLaunching:(UIApplication*)application {TTNavigator* navigator = [TTNavigator navigator]; navigator.window = [[[UIWindow alloc] initWithFrame:TTScreenBounds()] autorelease]; TTURLMap* map = navigator.URLMap;...[map from:@"tt://tabBar" toSharedViewController:[TabBarController class]]; [map from:@"tt://menu/(initWithMenu:)" toSharedViewController:[MenuController class]]; [map from:@"tt://myList" toViewController:[myListController class]]; if ...{[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://tabBar"]];} ***Sorry if code unclear – user1188849 May 29 '12 at 13:24