Please help!


#1

so here is my code for BNRAppDelegate.m

#import “BNRAppDelegate.h”

// Helper function to fetch the path to our to-do data stored on disk
NSString *docPath()
{
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,
NSUserDomainMask, YES);
return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@“data.td”];
}

@implementation BNRAppDelegate
#pragma mark - Table View management

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    // Because this table view only has one section,
    // the number of rows in it is equal to the number
    // of items in our task array
    return [tasks count];
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    // To improve performance, we reconfigure cells in memory
    // that have scrolled off the screen and hand them back
    // with new contents instead of always creating new cells.
    // First, we check to see if there’s a cell available for reuse.
    UITableViewCell *c = [taskTable dequeueReusableCellWithIdentifier:@“Cell”];

    if (!c) {
    // …and only allocate a new cell if none are available
    c = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
    reuseIdentifier:@“Cell”];
    }

    // Then we (re)configure the cell based on the model object,
    // in this case our todoItems array
    NSString *item = [tasks objectAtIndex:[indexPath row]];
    [[c textLabel] setText:item];

    // and hand back to the table view the properly configured cell
    return c;

}
#pragma mark - Application delegate callbacks

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Attempt to load an existing to-do dataset from an array stored to disk.
    NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
    if (plist) {
    // If there was a data set available, copy it into our instance variable.
    tasks = [plist mutableCopy];
    } else {
    // Otherwise, just create an empty one to get us started.
    tasks = [[NSMutableArray alloc] init];
    }

    // Is tasks empty?
    if ([tasks count] == 0) {
    // Put some strings in it
    [tasks addObject:@“Walk the dogs”];
    [tasks addObject:@“Feed the hogs”];
    [tasks addObject:@“Chop the logs”];
    }

    // Create and configure the UIWindow instance
    // A CGRect is a struct with an origin (x,y) and size (width,height)
    CGRect windowFrame = [[UIScreen mainScreen] bounds];
    UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
    [self setWindow:theWindow];

    // Define the frame rectangles of the three UI elements
    // CGRectMake() creates a CGRect from (x, y, width, height)
    CGRect tableFrame = CGRectMake(0, 80, 320, 380);
    CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
    CGRect buttonFrame = CGRectMake(228, 40, 72, 31);

    // Create and configure the table view
    taskTable = [[UITableView alloc] initWithFrame:tableFrame
    style:UITableViewStylePlain];
    [taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    // Make this object the table view’s dataSource
    [taskTable setDataSource:self];

    // Create and configure a rounded rect Insert button
    insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [insertButton setFrame:buttonFrame];

    // Buttons behave usong a target/action calback
    // Configure the Insert button’s action to call this object’s -addTask: method
    [insertButton addTarget:self
    action:@selector(addTask:)
    forControlEvents:UIControlEventTouchUpInside];

    • (void)addTask:(id)sender
      {
      // Get the to-do item
      NSSTring *t = [taskField text];

      // Quit here if taskField is empty
      if ([t isEqualToStringL@""]) {
      return;
      }

      // Add it to our working array
      [tasks addObject:t];
      // Refresh the table so that the new item shows up
      [taskTable reloadData];
      // And clear out the text field
      [taskField setText:@""];
      // Dismiss the keyboard
      [taskField resignFirstResponder];
      }

    // Give the button a title
    [insertButton setTitle:@"Insert"
    forState:UIControlStateNormal];

    // Add our three UI elements to the window
    [[self window] addSubview:taskTable];
    [[self window] addSubview:taskField];
    [[self window] addSubview:insertButton];

    // Finalize the window and put it on the screen
    [[self window] setBackgroundColor:[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

my problem is
-(void)addTask:(id)sender
it says code has failed use of undeclared identifier 'addTask’
what did i do wrong i have redone my program 4 times and it says the same thing i checked it 10 times each time and nothing is wrong with it please help


#2

Next time, please post your code between the Code tags like this:

[code]
// Private details
@interface BNRAppDelegate ()
{
void addTask:sender;
}

@implementation BNRAppDelegate

  • (void)addTask:(id)sender
    {

    }

    @end
    [/code]Meanwhile check to make sure that addTask: method is declared before it is referenced.

#3

[code]#import “BNRAppDelegate.h”

// Helper function to fetch the path to our to-do data stored on disk
NSString *docPath()
{
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,
NSUserDomainMask, YES);
return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@“data.td”];
}

@implementation BNRAppDelegate
#pragma mark - Table View management

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    // Because this table view only has one section,
    // the number of rows in it is equal to the number
    // of items in our task array
    return [tasks count];
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    // To improve performance, we reconfigure cells in memory
    // that have scrolled off the screen and hand them back
    // with new contents instead of always creating new cells.
    // First, we check to see if there’s a cell available for reuse.
    UITableViewCell *c = [taskTable dequeueReusableCellWithIdentifier:@“Cell”];

if (!c) {
// …and only allocate a new cell if none are available
c = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@“Cell”];
}

// Then we (re)configure the cell based on the model object,
// in this case our todoItems array
NSString *item = [tasks objectAtIndex:[indexPath row]];
[[c textLabel] setText:item];

// and hand back to the table view the properly configured cell
return c;

}
#pragma mark - Application delegate callbacks

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Attempt to load an existing to-do dataset from an array stored to disk.
    NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
    if (plist) {
    // If there was a data set available, copy it into our instance variable.
    tasks = [plist mutableCopy];
    } else {
    // Otherwise, just create an empty one to get us started.
    tasks = [[NSMutableArray alloc] init];
    }

// Is tasks empty?
if ([tasks count] == 0) {
// Put some strings in it
[tasks addObject:@“Walk the dogs”];
[tasks addObject:@“Feed the hogs”];
[tasks addObject:@“Chop the logs”];
}

// Create and configure the UIWindow instance
// A CGRect is a struct with an origin (x,y) and size (width,height)
CGRect windowFrame = [[UIScreen mainScreen] bounds];
UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
[self setWindow:theWindow];

// Define the frame rectangles of the three UI elements
// CGRectMake() creates a CGRect from (x, y, width, height)
CGRect tableFrame = CGRectMake(0, 80, 320, 380);
CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
CGRect buttonFrame = CGRectMake(228, 40, 72, 31);

// Create and configure the table view
taskTable = [[UITableView alloc] initWithFrame:tableFrame
style:UITableViewStylePlain];
[taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];

// Make this object the table view’s dataSource
[taskTable setDataSource:self];

// Create and configure a rounded rect Insert button
insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[insertButton setFrame:buttonFrame];

// Buttons behave usong a target/action calback
// Configure the Insert button’s action to call this object’s -addTask: method
[insertButton addTarget:self
action:@selector(addTask:)
forControlEvents:UIControlEventTouchUpInside];

  • (void)addTask:(id)sender
    {
    // Get the to-do item
    NSSTring *t = [taskField text];

// Quit here if taskField is empty
if ([t isEqualToStringL@""]) {
return;
}

// Add it to our working array
[tasks addObject:t];
// Refresh the table so that the new item shows up
[taskTable reloadData];
// And clear out the text field
[taskField setText:@""];
// Dismiss the keyboard
[taskField resignFirstResponder];
}

// Give the button a title
[insertButton setTitle:@"Insert"
forState:UIControlStateNormal];

// Add our three UI elements to the window
[[self window] addSubview:taskTable];
[[self window] addSubview:taskField];
[[self window] addSubview:insertButton];

// Finalize the window and put it on the screen
[[self window] setBackgroundColor:[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[/code]

like this??

i think it was declared there is no other problems with the code


#4

Please post the interface file (BNRAppDelegate.h) as well as the original error message itself.


#5

[code]#import <UIKit/UIKit.h>

// Declare a helper function that we will use to get a path
// to the location on disk where we can save the do-to list
NSString *docPath(void);

@interface BNRAppDelegate : UIResponder <UIApplicationDelegate, UITableViewDataSource>
{
UITableView *taskTable;
UITextField *taskField;
UIButton *insertButton;

NSMutableArray *tasks;

}

  • (void)addTask:(id)sender;

@property (strong, nonatomic) UIWindow *window;

@end [/code]

[code]#import “BNRAppDelegate.h”

// Helper function to fetch the path to our to-do data stored on disk
NSString *docPath()
{
NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory,
NSUserDomainMask, YES);
return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@“data.td”];
}

@implementation BNRAppDelegate
#pragma mark - Table View management

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    // Because this table view only has one section,
    // the number of rows in it is equal to the number
    // of items in our task array
    return [tasks count];
    }

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    // To improve performance, we reconfigure cells in memory
    // that have scrolled off the screen and hand them back
    // with new contents instead of always creating new cells.
    // First, we check to see if there’s a cell available for reuse.
    UITableViewCell *c = [taskTable dequeueReusableCellWithIdentifier:@“Cell”];

if (!c) {
// …and only allocate a new cell if none are available
c = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@“Cell”];
}

// Then we (re)configure the cell based on the model object,
// in this case our todoItems array
NSString *item = [tasks objectAtIndex:[indexPath row]];
[[c textLabel] setText:item];

// and hand back to the table view the properly configured cell
return c;

}
#pragma mark - Application delegate callbacks

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Attempt to load an existing to-do dataset from an array stored to disk.
    NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
    if (plist) {
    // If there was a data set available, copy it into our instance variable.
    tasks = [plist mutableCopy];
    } else {
    // Otherwise, just create an empty one to get us started.
    tasks = [[NSMutableArray alloc] init];
    }

// Is tasks empty?
if ([tasks count] == 0) {
// Put some strings in it
[tasks addObject:@“Walk the dogs”];
[tasks addObject:@“Feed the hogs”];
[tasks addObject:@“Chop the logs”];
}

// Create and configure the UIWindow instance
// A CGRect is a struct with an origin (x,y) and size (width,height)
CGRect windowFrame = [[UIScreen mainScreen] bounds];
UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
[self setWindow:theWindow];

// Define the frame rectangles of the three UI elements
// CGRectMake() creates a CGRect from (x, y, width, height)
CGRect tableFrame = CGRectMake(0, 80, 320, 380);
CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
CGRect buttonFrame = CGRectMake(228, 40, 72, 31);

// Create and configure the table view
taskTable = [[UITableView alloc] initWithFrame:tableFrame
style:UITableViewStylePlain];
[taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];

// Make this object the table view’s dataSource
[taskTable setDataSource:self];

// Create and configure a rounded rect Insert button
insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[insertButton setFrame:buttonFrame];

// Buttons behave usong a target/action calback
// Configure the Insert button’s action to call this object’s -addTask: method
[insertButton addTarget:self
action:@selector(addTask:)
forControlEvents:UIControlEventTouchUpInside];

  • (void)addTask:(id)sender --------------------> [color=#FFFF00]use of undeclared identifier ‘addTask’[/color]
    {
    // Get the to-do item
    NSSTring *t = [taskField text];

// Quit here if taskField is empty
if ([t isEqualToStringL@""]) {
return;
}

// Add it to our working array
[tasks addObject:t];
// Refresh the table so that the new item shows up
[taskTable reloadData];
// And clear out the text field
[taskField setText:@""];
// Dismiss the keyboard
[taskField resignFirstResponder];
}

// Give the button a title
[insertButton setTitle:@"Insert"
forState:UIControlStateNormal];

// Add our three UI elements to the window
[[self window] addSubview:taskTable];
[[self window] addSubview:taskField];
[[self window] addSubview:insertButton];

// Finalize the window and put it on the screen
[[self window] setBackgroundColor:[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 [/code]

i really thank you for helping me or trying to help me