Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Draw This
($0.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 07-28-2009, 11:16 PM   #270 (permalink)
wizowsky
Registered Member
 
Join Date: Jul 2009
Posts: 2
wizowsky is on a distinguished road
Question movieplayer not playing from tableview

I'm a newbie with iPhone dev and I've been developing a simple application on TV Schedule Guide that could play short video trailers. I applied what OneTeamDev's code on implimenting tab bar controller programatically and it works like a charm. so my application has a tab bar controller that displays a list of tv show scheds in a tableview. each show should play a trailer when tap but apparently it ain't. i'm using a streamlined code from Apple's movieplayer sample code and it's already been taking me ages to make it work. Perhaps, you guys could throw me some help.

here's my AppDelegate code:

TVSchedAppDelegate.h

Code:
#import <UIKit/UIKit.h>
#import "AllShowsViewController.h"

@class MovieViewController;

@interface TVSchedAppDelegate : NSObject <UIApplicationDelegate> {
    IBOutlet UIWindow *window;
    UITabBarController *tabBarController;
    AllShowsButtonController *allShowsViewController;
    UITableViewController *mySecondTableViewController;
	MovieViewController *mViewController;
	
		
}

-(void)applicationDidFinishLaunching:(UIApplication *)application;
-(void)dealloc;

@property (nonatomic, retain) MovieViewController *mViewController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@property (nonatomic, retain) UITableViewController *allShowsViewController;
@property (nonatomic, retain) UITableViewController *mySecondTableViewController;

@end
TVSchedAppDelegate.m

Code:
#import "TVSchedAppDelegate.h"
#import "MovieViewController.h"


@implementation TVSchedAppDelegate

@synthesize window, allShowsViewController, mySecondTableViewController, tabBarController;
@synthesize mViewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    
	
    tabBarController = [[UITabBarController alloc] init];          // creates your tab bar so you can add everything else to it
	
	allShowsViewController = [[AllShowsButtonController alloc] init];               // creates your table view - this should be a UIViewController with a table view in it, or UITableViewController
	UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:allShowsViewController] autorelease];
	allShowsViewController.title=@"TV Shows";
	tableNavController.tabBarItem.image = [UIImage imageNamed:@"home_20.png"];
	[allShowsViewController release];     
	
	// creates your table view's navigation controller, then adds the view controller you made. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.
	
	mySecondTableViewController = [[UITableViewController alloc] init];   
	UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:mySecondTableViewController] autorelease];
	[mySecondTableViewController release];                                                    // does exactly the same as the first round, but for your second tab at the bottom of the bar.
	
	tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; //add both of your navigation controllers to the tab bar. You can put as many controllers on as you like, but they will turn into the more button like in the iPod program.
	
	[window addSubview:tabBarController.view];                                              // adds the tab bar's view property to the window
	[window addSubview:mViewController.view];
	[window makeKeyAndVisible]; 
}

- (void)dealloc {
    [tabBarController release];
	[mViewController release];
	[window release];
	[super dealloc];
}


@end
AllShowsViewController.h
Code:
#import <UIKit/UIKit.h>
#import "MovieViewController.h"
#define kShowValueTag 1
#define kScheduleValueTag 2
#define kRatingTag 3


@interface AllShowsButtonController : UITableViewController  <UITableViewDelegate, UITableViewDataSource>
{
	NSArray *shows;
	UIImage *rowImage;
	
	MovieViewController *mViewController;
	
}

@property (nonatomic, retain) NSArray *shows;
@property (nonatomic, retain) UIImage *rowImage;
@property (nonatomic, retain) MovieViewController *mViewController;
@end
AllShowsViewController.m
Code:
#import "AllShowsViewController.h"
#import "TVSchedAppDelegate.h"

@implementation AllShowsButtonController
@synthesize shows, mViewController, rowImage;


- (void)viewDidLoad {
	
	NSArray *array = [[NSArray alloc] initWithObjects:@"TV Show 1",
					  @"TV Show 2", @"TV Show 3", @"TV Show 4", @"TV Show 5", @"TV Show 6", @"TV Show 6", nil];
	
	AllShowsButtonController *allShowsButtonController = [[AllShowsButtonController alloc] initWithStyle:UITableViewStylePlain];
	[allShowsButtonController release];
	
	self.shows = array;
	
	[array release];
	
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.shows count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *AllShowsButtonCellIdentifer = @"AllShowsButtonCellIdentifer";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:AllShowsButtonCellIdentifer];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:AllShowsButtonCellIdentifer] autorelease];
		
		// Line row for Show's Name
		UILabel *showValue = [[UILabel alloc] initWithFrame:showValueRect];
		showValue.tag = kShowValueTag;
		[cell.contentView addSubview:showValue];
		[showValue release];
	}
	
	//Configure cell
	NSUInteger row = [indexPath row];
	
	//Configure line row for Show
	NSString *rowString = [shows objectAtIndex:row];
	UILabel *show = (UILabel *)[cell.contentView viewWithTag:kShowValueTag];
	show.text = rowString;
	[rowString release];

    return cell;
}

#pragma mark -
#pragma mark Table View Delegate Methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	[mViewController playMovie:self];
}

- (void)dealloc {
    [super dealloc];
}


@end
wizowsky is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,015
Threads: 93,863
Posts: 401,917
Top Poster: BrianSlick (7,962)
Welcome to our newest member, udrescubogdan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.