Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dogwong

macrumors newbie
Original poster
May 17, 2010
6
0
I follow this viedo (http://www.youtube.com/watch?v=zu31fCIwt1E) and make a simular apps
but it throw a error:
"expected expression before 'ThirdViewController'"
on the line
"[self presentModalViewController:ThirdViewController animated:YES];"

I don't know what it mean....
is it because the simulator version? (i use 3 but the video use 2)
and how to switch view if this way is wrong

Please help....
and sorry for my bad English
thanks
 

dogwong

macrumors newbie
Original poster
May 17, 2010
6
0
(project name is SWF)

here is the code:

SWFAppDelegate.h
Code:
#import <UIKit/UIKit.h>

@class SWFViewController;

@interface SWFAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    SWFViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet SWFViewController *viewController;

@end

SWFAppDelegate.m
Code:
#import "SWFAppDelegate.h"
#import "SWFViewController.h"

@implementation SWFAppDelegate

@synthesize window;
@synthesize viewController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}


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


@end

SWFViewController.h
Code:
#import <UIKit/UIKit.h>
#import "SecondViewController.h"

@interface SWFViewController : UIViewController {
	IBOutlet UIButton *about;
	IBOutlet SecondViewController *SecondViewController;
}

- (IBAction)showAbout;

@end

SWFViewController.m
Code:
#import "SWFViewController.h"


@implementation SWFViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/



// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


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

- (IBAction)showAbout {
	[COLOR="DarkOrange"][self presentModalViewController:SecondViewController animated:YES];[/COLOR]
// this line have error
}

@end

SecondViewController.h
Code:
#import <UIKit/UIKit.h>
#import "ThirdViewController.h"


@interface SecondViewController : UIViewController {
	
	IBOutlet ThirdViewController *ThirdViewController;
	
}

- (IBAction)gotoThirdView;

- (IBAction)gotoBack;

@end

SecondViewController.h

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


@interface SecondViewController : UIViewController {
	
	IBOutlet ThirdViewController *ThirdViewController;
	
}

- (IBAction)gotoThirdView;

- (IBAction)gotoBack;

@end

SecondViewController.m

Code:
#import "SecondViewController.h"


@implementation SecondViewController

- (IBAction)gotoThirdView{
	[self presentModalViewController:ThirdViewController animated:YES];
}

- (IBAction)goBack{
	[self dismissModalViewControllerAnimated:YES];
}
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


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


[COLOR="darkorange"]@end[/COLOR] warning: incomplete implementation of class 'SecondViewController'

ThirdViewController.h
Code:
#import <UIKit/UIKit.h>


@interface ThirdViewController : UIViewController {
	
	
	
}

- (IBAction)goBack;

@end

ThirdViewController.m

Code:
#import "ThirdViewController.h"


@implementation ThirdViewController

- (IBAction)goBack{
	[self dismissModalViewControllerAnimated:YES];
}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


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


@end


SWFViewController.xib

a button: title: about
connection: Touch up inside - file's owner showAbout

SecondView.xib

a label, text: Second
a button, title: go to third
connection: Touch up inside - file's owner gotoThirdView
a button, title: back
connection: Touch up inside - file's owner gotoBack

ThirdView.xib
a label, text: Third
a button, title: Back
connection: Touch up inside - file's owner gotoBack


Thanks
 

Svinja

macrumors newbie
Oct 27, 2008
27
0
Hi,
as dejo said...this part of the code is wrong:
Code:
- (IBAction)gotoThirdView
{
	[self presentModalViewController:ThirdViewController animated:YES];
}
ThirdViewController is a class, you must use instance of that class in order for this to work...for example

Code:
- (IBAction)gotoThirdView
{
        ThirdViewController *thirdViewController=[[ThirdViewController alloc] init];
	[self presentModalViewController:thirdViewController animated:YES];
        [thirdViewController release];
}
notice the capital letters...
 

dogwong

macrumors newbie
Original poster
May 17, 2010
6
0
Hi,
as dejo said...this part of the code is wrong:
Code:
- (IBAction)gotoThirdView
{
	[self presentModalViewController:ThirdViewController animated:YES];
}
ThirdViewController is a class, you must use instance of that class in order for this to work...for example

Code:
- (IBAction)gotoThirdView
{
        ThirdViewController *thirdViewController=[[ThirdViewController alloc] init];
	[self presentModalViewController:thirdViewController animated:YES];
        [thirdViewController release];
}
notice the capital letters...

Build and Run succeeded.

But when i try that, it is normal if I switch between first and second view, and it crash when I switch to third view, what's wrong?
and is that any way to find what make the apps carsh?
Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.