14 Oct 2008, 01:09
Generic-user-small

Jared (8 posts)

I have now went through the tutorial videos 3 times from video 1 to 22:33 into video 2 and each time at this point the IngredientsViewController is not working. I cannot figure out what I am doing wrong. I know everything up to the point where I replace the log file is right.

NSLog(@”cell clicked {%d, %d}”, indexPath.row, indexPath.section);

I have the latest SDK with the iPhone Sim version 2.1 Firmware.

The only issues but not errors are these two flags.

!http://farm4.static.flickr.com/3013/2939438593_1c514fcc71_o.png!

!http://farm4.static.flickr.com/3030/2939438621_be78e1a800_o.png!

Here is all my code if it is needed.

// // RecipesAppDelegate.h // Recipes // // Created by Jared on 10/13/08. // Copyright MyCompanyName 2008. All rights reserved. //

import <UIKit/UIKit.h>

@class RecipesViewController; @class IngredientsViewController;

@interface RecipesAppDelegate : NSObject { UIWindow *window; RecipesViewController *recipesController; IBOutlet UINavigationController *navController; IBOutlet IngredientsViewController *ingredientsController; }

@property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet RecipesViewController *recipesController;

  • (void)recipeClicked:(NSString *)recipeName;

@end

// // RecipesAppDelegate.m // Recipes // // Created by Jared on 10/13/08. // Copyright MyCompanyName 2008. All rights reserved. //

import “RecipesAppDelegate.h”

#import “RecipesViewController.h”

@implementation RecipesAppDelegate

@synthesize window; @synthesize recipesController;

  • (void)recipeClicked:(NSString *)recipeName { [navController pushViewController:ingredientsController animated:YES]; }

  • (void)applicationDidFinishLaunching:(UIApplication *)application {
    navController.viewControllers = [NSArray arrayWithObject:recipesController];

    // Override point for customization after app launch
    [window addSubview:navController.view]; [window makeKeyAndVisible]; }

  • (void)dealloc { [recipesController release]; [window release]; [super dealloc]; }

@end

// // RecipesViewController.h // Recipes // // Created by Jared on 10/13/08. // Copyright MyCompanyName 2008. All rights reserved. //

import <UIKit/UIKit.h>

@class RecipesAppDelegate;

@interface RecipesViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> { IBOutlet RecipesAppDelegate *appDelegate;

}

@end

// // RecipesViewController.m // Recipes // // Created by Jared on 10/13/08. // Copyright MyCompanyName 2008. All rights reserved. //

import “RecipesViewController.h”

@implementation RecipesViewController

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”recipeCell”]; if(nil == cell) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier: @”recipeCell”] autorelease]; } if(indexPath.row == 0) { cell.text = @”Cherry Pie”; } else if(indexPath.row == 1) { cell.text = @”Cake”; } else if(indexPath.row == 2) { cell.text = @”Cookie”; } return cell; }

  • (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section { return 3; }

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath { [appDelegate recipeClicked:[[tableView cellForRowAtIndexPath:indexPath] text]]; }

/* // Override initWithNibName:bundle: to load the view using a nib file then perform additional 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. - (void)loadView { } */

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

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); }

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Releases the view if it doesn’t have a superview // Release anything that’s not essential, such as cached data }

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

@end

// // IngredientsViewController.h // Recipes // // Created by Jared on 10/13/08. // Copyright 2008 MyCompanyName. All rights reserved. //

import <UIKit/UIKit.h>

@interface IngredientsViewController : UIViewController {

}

@end

// // IngredientsViewController.m // Recipes // // Created by Jared on 10/13/08. // Copyright 2008 MyCompanyName. All rights reserved. //

import “IngredientsViewController.h”

@implementation IngredientsViewController

  • (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *) indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil]; return cell; }

  • (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section { return 1; }

/* // Override initWithNibName:bundle: to load the view using a nib file then perform additional 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. - (void)loadView { } */

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

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); }

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Releases the view if it doesn’t have a superview // Release anything that’s not essential, such as cached data }

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

@end

14 Oct 2008, 03:13
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi Jared,

Have you compared your code to the sample code that comes with the screencasts?

I have not had time to go over the code you have pasted here but I think you might find some clues to the problem by doing a diff between your code and the sample code. On the command line (in Terminal.app);

$ cd directory with both your code and the example code $ opendiff yourcode samplecode

HTH

14 Oct 2008, 14:04
Generic-user-small

Jared (8 posts)

Sorry I did not notice the code link on the page. I did not mean for you to go through all of my code I just wanted to make sure that I gave as much info as possible so that there would not have to be a comment saying “well you did not give enough info”

I have now found a downloaded the sample code and will check it out.

Thank You for the help Bill Dudney.

18 Oct 2008, 12:41
Generic-user-small

Jared (8 posts)

I do not know what the issue was but I downloaded the sample code and just now sat down to look at the code so I opened my code with xCode and ran the program. It worked. I did not change any code so I have no idea what was wrong.

18 Oct 2008, 13:38
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi Jared,

If you do a clean and rebuild you will get the warnings again.

I suspect that you are missing an import. But I would still make sure to do the opendiff to check for the delta between your code and the SC’s code.

Good luck!

12 Jan 2009, 04:19
Generic-user-small

John (2 posts)

I had the same issue, Once I added the UITableViewDataSource prototype to IngredientsViewController, the problem went away. I’m not sure why this prototype implementation would cause/fix those two warning/error messages you referenced, but it fixed it nonetheless for me.

import <UIKit/UIKit.h>

@interface IngredientsViewController : UIViewController {

}

@end

12 Jan 2009, 04:20
Generic-user-small

John (2 posts)

FYI - for some reason the forum rendered my post above incorrectly, it changed the casing of some of the code I pasted. Good luck.

11 Mar 2009, 06:17
Generic-user-small

Al Chang (1 post)

fyi.. There’s a few differences between the code following only screencast instructions and sample code. This will result in some compile errors (at least in 2.2.1 and the latest xcode).

In RecipesAppDelegate.m: #import “IngredientsViewController.h” is in list of #imports While it is seen in the code in the screencast, but the voiceover doesn’t mention to add it.

In IngredientsViewController.h:

has been added to the interface prototype. This is in the code in the screencast, but the voiceover doesn't mention to add it.
  You must be logged in to comment