Video does not play from viewDidLoad - ios

I am building an iPhone 6 app for a friend's store. I wanted to have a video intro automatically playing when the initial view controller starts. I get no sound or audio.
I have on my storyboard a UIViewController, and in it a view that I re-classified as AVPlayerClass
I have also added added cupcake1.mov (QuickTime format) under "Supporting Files".
// AppDelegate.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
//
// AppDelegate.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
//
// ViewController.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import "AVPlayerClass.h"
#class AVPlayer;
#class AVPlayerClass;
#interface ViewController : UIViewController
#property (nonatomic, strong) AVPlayer *player;
#property (nonatomic, strong) AVPlayerClass *playerView;
#end
//
// ViewController.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize player;
#synthesize playerView;
- (void)viewDidLoad {
[super viewDidLoad];
[self setupMovie];
}
- (void)setupMovie
{
NSURL *url = [[NSBundle mainBundle]URLForResource:#"cupcake1" withExtension:#"mov"];
self.player = [AVPlayer playerWithURL: url];
[self.playerView setMovieToPlayer:player];
[self.player play];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
//
// AVPlayerClass+.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#class AVPlayer;
#interface AVPlayerClass : UIView
#property (nonatomic, retain) AVPlayer* player;
- (void)setMovieToPlayer:(AVPlayer*)player;
#end
//
// AVPalyerClass.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "AVPlayerClass.h"
#implementation AVPlayerClass
+ (Class)layerClass
{
return [AVPlayerLayer class];
}
-(AVPlayer*)player
{
return [(AVPlayerLayer*) [self layer] player];
}
- (void)setMovieToPlayer:(AVPlayer *)player
{
[(AVPlayerLayer*)[self layer] setPlayer: player];
}
#end
//
// main.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

I just created a sample project just like yours and have my movie playing and used the MPMoviePlayerController class.
I launched Xcode and created a new iOS application project based on the Single View Application template.
I took a random sample movie file from vimeo, downloaded it, and copied it to my project calling it "movie.mp4".
In the ViewController.m I followed the following three steps:
#import <MediaPlayer/MediaPlayer.h>>
added a movieplayer property:
#property (nonatomic) MPMoviePlayerController *moviePlayer;
in viewDidLoad I added the following code:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"movie" ofType:#"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
self.moviePlayer.shouldAutoplay = YES;
[self.moviePlayer setFullscreen:YES animated:YES];
UIView *videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[self.moviePlayer.view setFrame:videoView.bounds];
[videoView addSubview:self.moviePlayer.view];
[self.view addSubview:videoView];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
}
I built and run and I am able to watch the movie and go fullscreen.
I tested on device and the movie plays.
If you get this far then you can adjust to your specific UI.
Hope this helps.

Related

Apple Watch - Watch Kit - Delegate method not being called

Ok so I am attempting to pass an int to another interface, edit the int and give it back to the original interface. I am trying to use a delegate to achieve this and I believe I have it setup correctly and it appears the method is not being called when its supposed to.
//
// InterfaceController.h
// DelegateTest WatchKit Extension
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import "SecondController.h"
#interface InterfaceController : WKInterfaceController <DelegateTest>
{
NSTimer *Update;
}
#property (strong, nonatomic) IBOutlet WKInterfaceLabel *FirstControllerLabel;
#property (nonatomic,assign) int FirstInteger;
#property (nonatomic,assign) int RecievedInteger;
#property (nonatomic,assign) NSString *PassString;
#end
// InterfaceController.m
// DelegateTest WatchKit Extension
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import "InterfaceController.h"
#interface InterfaceController()
#end
#implementation InterfaceController
#synthesize FirstInteger;
#synthesize RecievedInteger;
#synthesize PassString;
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
}
-(void)UpdateVoid
{
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (void)willActivate {
SecondController *interfaceController;
interfaceController.delegate = self;
Update = [NSTimer timerWithTimeInterval:1.0 target:self selector:#selector(UpdateVoid) userInfo:nil repeats:YES];
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
-(void)DelegateMethod:(int)ReturningInt
{
[self popController];
FirstInteger = ReturningInt;
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (IBAction)UpButton {
FirstInteger++;
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (IBAction)DownButton {
FirstInteger--;
self.FirstControllerLabel.text = [NSString stringWithFormat:#"%i", FirstInteger];
}
- (IBAction)PassDataButton {
PassString = [NSString stringWithFormat:#"%i", FirstInteger];
[self pushControllerWithName:#"SecondController" context:PassString];
}
#end
//
// SecondController.h
// DelegateTest
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
//This declaration of delegate.
#protocol DelegateTest <NSObject>
-(void) DelegateMethod:(int)ReturningInt;
#end
#interface SecondController : WKInterfaceController
{
id delegate;
}
#property (nonatomic, assign) id <DelegateTest> delegate;
#property (strong, nonatomic) IBOutlet WKInterfaceLabel *SecondLabel;
#property (nonatomic,assign) NSString *RecievedString;
#property (nonatomic, assign) int FirstReceivedInteger;
#end
//
// SecondController.m
// DelegateTest
//
// Created by Rohan Hodge on 20/10/2015.
// Copyright © 2015 Hodge Development. All rights reserved.
//
#import "SecondController.h"
#import "InterfaceController.h"
#interface SecondController ()
#end
#implementation SecondController
#synthesize SecondLabel;
#synthesize FirstReceivedInteger;
#synthesize RecievedString;
#synthesize delegate = _delegate;
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
//This is where I receive the int inside of a string and split it from the string so I can change it
RecievedString = context;
FirstReceivedInteger = [RecievedString intValue];
// Configure interface objects here.
}
- (void)willActivate {
self.SecondLabel.text = [NSString stringWithFormat:#"%i",FirstReceivedInteger];
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (IBAction)UpButton {
FirstReceivedInteger++;
self.SecondLabel.text = [NSString stringWithFormat:#"%i",FirstReceivedInteger];
}
- (IBAction)DownButton {
FirstReceivedInteger--;
self.SecondLabel.text = [NSString stringWithFormat:#"%i",FirstReceivedInteger];
}
//This is a button that is ment to pass back the int.
- (IBAction)ReturnToOriginalInterface:(id)sender{
[self.delegate DelegateMethod:FirstReceivedInteger];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
#end
I'm new to Stack Overflow, Sorry about the messy code formatting.
P.S I use the Arrow in the top left of the interface to return to the original Interface. Also am using Objective-C
Thanks in advance.
You need to set a property or method to change in your controller (that your first controller will change) and you get back the result with a delegate pattern.
You're attempting to do this in a Watch app, yes? I don't know that delegates don't work, but when I did this for my Watch app, I used the context parameter of WKInterfaceController::presentControllerWithName:context:.
context is a NSDictionary of the values you want to pass around. One of those values could be a pointer to the presenting controller.
So, trying to decipher what you're attempting in your app, I believe the proper thing to do is:
In the ORIGINAL WKInterfaceController:
- (IBAction)buttonThatOpensOtherIC
{
NSDictionary *context = #{
#"firstController" : self,
};
[self pushControllerWithName:#"Other IC"
context:context];
}
}
In the OTHER WKInterfaceController:
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
if (context)
{
self.originalInterfaceController = context[#"firstController"];
}
}
//This is the button that calls the delegate method.
- (IBAction)ReturnToOriginalInterface:(id)sender
{
// [self.delegate DelegateMethod:FirstReceivedInteger];
if (self.originalInterfaceController) {
self.originalInterfaceController.firstInteger = self.returningInt;
}
[self popController];
}
*Note the use of awakeWithContext: in the OTHER interface controller.
DISCLAIMER #1: I haven't executed this code, so there may be a typo in it. It is an adaptation for you of working code I do use.
DISCLAIMER #2: I haven't updated my app for WatchOS 2. I doubt this part of things changed, but it is possible.

UIWebView not appearing - Xcode 6

my project won't show the web view no matter what code i try use. I even tried a youtube tutorial. I know this question has been asked many times but it doesn't make sense to me. I used this tutorial https://www.youtube.com/watch?v=AmMF7hWrYZk
Heres my code
If you need more detail please ask me. I'm knew to objective c
ViewController.m
// FirstViewController.m
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
ViewController.h
//
// FirstViewController.h
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIWebView *webView;
#end

Xcode error - unknown type name 'home'

this is my first question on stackoverflow.! Cheers.!
Please review my code from the link below. I have copy pasted appdelegate.h, appdelegate.m, viewcotroller.h&.m to a text document for reviewing purposes.
http://www.mediafire.com/view/85614p44t8eiqif/HomePageViewController.rtf
I will explain my problem in detail below.
I'm trying to recreate UICatalogue in a smaller scale all through code. I'm an app developement trainee. This is what I have done so far.
Keep in mind that my knowledge on Xcode and Objective-C is very limited. I'm using Xcode 5.1.1
I have created an instance variable (HPVC) for the Home Page view controller "HomePageViewController" in AppDelegate.h
I have set this HPVC as rootviewcontroller.
Declared and defined some instance variables.
*But I'm stuck in a loop from what I have searched so far.
I understand the importing has ended up in a loop. But I cant fix it.
Please check this and give me an answer. I can start my project If I can clear this obstacle.
Here is a screenshot of the error
http://www.mediafire.com/view/yjmwbb2dcb7rymd/Error.png
//
// AppDelegate.h
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "HomePageViewController.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate>
{
HomePageViewController *HPVC;
}
#property (strong, nonatomic) UIWindow *window;
#end
//
// AppDelegate.m
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
HPVC=[[HomePageViewController alloc]initWithNibName:#"HomePageViewController" bundle:nil];
self.window.rootViewController=HPVC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
//
// HomePageViewController.h
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface HomePageViewController : UIViewController
//Background Images for all the Views.
#property(nonatomic,strong) UIImageView *HomePageBG;
#property(nonatomic,strong) UIImageView *Page1ButtonBG;
#property(nonatomic,strong) UIImageView *Page2ControlsBG;
#property(nonatomic,strong) UIImageView *Page3TextFieldBG;
#property(nonatomic,strong) UIImageView *Page4TextView;
#property(nonatomic,strong) UIImageView *Page5Images;
#property(nonatomic,strong) UIImageView *Page6Segments;
#property(nonatomic,strong) UIImageView *Page7Toolbar;
#property(nonatomic,strong) UIImageView *Page8Alerts;
#property(nonatomic,strong) UIImageView *Page9Transitions;
//Home Page Elements.
#property(nonatomic,strong) UILabel *lblHomePageHeader;
#property(nonatomic,strong) UILabel *lblHomePageWelcome;
#property(nonatomic,strong) UIButton *BtnPage1;
#property(nonatomic,strong) UIButton *BtnPage2;
#property(nonatomic,strong) UIButton *BtnPage3;
#property(nonatomic,strong) UIButton *BtnPage4;
#property(nonatomic,strong) UIButton *BtnPage5;
#property(nonatomic,strong) UIButton *BtnPage6;
#property(nonatomic,strong) UIButton *BtnPage7;
#property(nonatomic,strong) UIButton *BtnPage8;
#property(nonatomic,strong) UIButton *BtnPage9;
#property(nonatomic,strong) UIButton *BtnChangeBGColor;
//Future Update. Add Button to change all button colors in Home Page.
#end
//
// HomePageViewController.m
// NewUICatalogue1
//
// Created by Roshith Balendran on 18/04/14.
// Copyright (c) 2014 Roshith Balendran. All rights reserved.
//
#import "HomePageViewController.h"
#interface HomePageViewController ()
#end
#implementation HomePageViewController
#synthesize HomePageBG;
#synthesize Page1ButtonBG;
#synthesize Page2ControlsBG;
#synthesize Page3TextFieldBG;
#synthesize Page4TextView;
#synthesize Page5Images;
#synthesize Page6Segments;
#synthesize Page7Toolbar;
#synthesize Page8Alerts;
#synthesize Page9Transitions;
#synthesize lblHomePageHeader;
#synthesize lblHomePageWelcome;
#synthesize BtnPage1;
#synthesize BtnPage2;
#synthesize BtnPage3;
#synthesize BtnPage4;
#synthesize BtnPage5;
#synthesize BtnPage6;
#synthesize BtnPage7;
#synthesize BtnPage8;
#synthesize BtnPage9;
#synthesize BtnChangeBGColor;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//Home Page Background image added.
HomePageBG=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
HomePageBG.image=[UIImage imageNamed:#"Red"];
[self.view addSubview:HomePageBG];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#end
everything is correct but you forgot to import #import "HomePageViewController.h" on app delegate.m class

NSLog not working when I make a method call in objective c

I'm working on my first ground-up iOS app. I'm sure I'm doing something wrong here, but I can't seem to ferret out the problem.
I have an app with some IBActions in it, which do two things:
1) Outputs some simple text via NSLog (to let me know the action worked) - this works okay (it outputs my text via NSLog)
2) Makes a call to a method in a custom class which should also output an NSLog statement. - this doesn't work (no text output via NSLog)
I'm also struggling a bit with where to create the instances of my classes so that they are accessible elsewhere in my code.
Here's the code:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController {
// Variables that you want to access globally go here?
Player *wizard;
Orc *grunty;
}
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
and
//
// ViewController.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "ViewController.h"
#import "Player.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)takePie:(id)sender{
// Player attempts to take the pie
// If Orc's health is > 0, don't let the player take the pie
// If the Orc's health is <= zero, let the player take the pie
NSLog(#"IBAction - player attempted to take the pie.");
[wizard takePie];
}
-(IBAction)castFireball:(id)sender{
NSLog(#"IBAction - player cast fireball.");
[wizard castFireball];
}
-(IBAction)attack:(id)sender{
NSLog(#"IBAction - player attacked.");
[wizard attackOrc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Player *wizard = [[Player alloc]init];
Orc *grunty = [[Orc alloc]init];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and
//
// Player.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <Foundation/Foundation.h>
#interface Player : NSObject
#property int maxHealth;
#property int currentHealth;
#property int armorClass;
#property int meleeToHitModifier;
-(void)setHeathBar;
-(void)attackOrc;
-(void)castFireball;
-(void)takePie;
#end
and
//
// Player.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "Player.h"
#implementation Player
#synthesize maxHealth;
#synthesize currentHealth;
#synthesize armorClass;
#synthesize meleeToHitModifier;
-(void)setHealthBar {
NSLog(#"Player health is 15");
return;
}
-(void)attackOrc {
// roll a d20
// add the "to hit" modifier
// compare the result to the orc's armor class
NSLog(#"Player - Player attached the Orc");
return;
}
-(void)castFireball{
NSLog(#"Player - Player casts Fireball");
return;
}
-(void)takePie{
NSLog(#"Player - Player attempts to take pie");
return;
}
#end
Note: I also have an Orc class defined, but it looks fairly identical to the player class shown.
Thanks in advance for the help!
-- Eddie
Your ViewController.h (which you should call by some more distinctive name, FYI) should look like this:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController
#property Player *wizard;
#property Orc *grunty;
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
Then in your ViewController.m, your viewDidLoadMethod should look like:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.wizard = [[Player alloc]init];
self.grunty = [[Orc alloc]init];
}
This should at least ensure you have an instantiated instance of Player that you can call methods on, so your NSLog should be reached.

Compile Errors in untouched AppDelegate.m

I have been creating a simple example app to demonstrate playing sound files in IOS.
For this I have created a very simple XCode project with one view controller. However, although my AppDelegate.h and .m files have remained unedited I am getting strange parse issues in the AppDelegate.m.
On the line #Implimentation the compiler tells me its missing '#end'.
On the line -(BOOL) application: (UIApplication ) application didFinishLaunchingWithOptions: (NSDictionary) launch options it tells me Expected ';' after method prototype.
The issues seem to stem from the #import "ViewController.h" reference in the AppDelegate.m file. As when I remove this these two errors go away, and get replaced with Receiver 'ViewController' for class message is a forward declaration, which is what I would expect with a missing import.
This is an odd problem. I've built several IOS apps before but never encountered this issue. For background info the project was created as a Single View App in XCode 4. I have properly lined the IBOutlets and Properties of the ViewController.h to the XIB in interface builder. I have also added in the AudioToolbox framework in via the build phases > Link Library with Libraries feature.
Here is the delegete and view controller files files
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
AppDelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) ViewController *viewController;
#end
ViewContoller.m
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#interface ViewController ()
SystemSoundID pig;
SystemSoundID cow;
SystemSoundID sheep;
SystemSoundID chicken;
#end
#implementation ViewController
#Synthesize but_cow, but_pig, but_sheep, but_chicken;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString * cowSoundURL= [[NSBundle mainBundle] pathForResource:#"cow" ofType: #"mp3"];
NSString * pigSoundURL= [[NSBundle mainBundle] pathForResource:#"pig" ofType: #"mp3"];
NSString * sheepSoundURL= [[NSBundle mainBundle] pathForResource:#"sheep" ofType: #"mp3"];
NSString * chiickenSoundURL= [[NSBundle mainBundle] pathForResource:#"chicken" ofType: #"mp3"];
AudioServicesCreateSystemSoundID(cowSoundURL, &cow);
AudioServicesCreateSystemSoundID(pigSoundURL, &pig);
AudioServicesCreateSystemSoundID( sheepSoundURL, &sheep);
AudioServicesCreateSystemSoundID(chickenSoundURL, &chicken);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//====================================================
/**
Called when a button is pressed
**/
//====================================================
-(IBAction)buttonPressed:(id)sender
{
if (sender == but_cow)
{
AudioServicesPlaySystem(cow);
}
else if (sender == but_sheep)
{
AudioServicesPlaySystem(sheep);
}
else if (sender == but_pig)
{
AudioServicesPlaySystem(pig);
}
else if (sender == but_chicken)
{
AudioServicesPlaySystem(chicken);
}
}//===================================================
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, retain) IBOutlet UIButton * but_cow;
#property (nonatomic, retain) IBOutlet UIButton * but_pig;
#property (nonatomic, retain) IBOutlet UIButton * but_sheep;
#property (nonatomic, retain) IBOutlet UIButton * but_chicken;
-(IBAction)buttonPressed:(id)sender;
Thanks very much for taking the time to read this.
ViewController.h seems to be missing an #end
The line:
#import "ViewController.h"
will basically copy in the entire file, so if there is an error in ViewController.h, it will show up everywhere that file is imported as well.
You are not adding #end in viewcontroller.h

Resources