PDA

View Full Version : Errors NESTED FUNCTONS ARE DISABLED




geiger10d
Jan 31, 2011, 10:40 PM
can someone tell me whats wrong?


NSInteger row - [indexPath row];
if (self.workoutsDetailViewController == nil) {
WorkoutsDetailViewController *aWorkoutDetail = [[WorkoutsDetailViewController alloc] initWithNibName:@"WorkoutsDetailView" bundle:nil];
self.workoutsDetailViewController = aWorkoutDetail;
[aWorkoutDetail release];
}
WorkoutsDetailViewController.title = [NSString stringWithFormat:@"X@", [workoutsArray objectAtIndex:.row]];

iScheduleFitnessAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.workoutsNavController pushViewController:workoutsDetailViewController animated:YES];



chown33
Jan 31, 2011, 11:34 PM
Insufficient context.

1. Provide the entire method or function, not just an isolated fragment.

2. Identify exactly which line the error message is referring to.

The "nested functions" error message usually results from a completely unrelated and possibly far distant syntax error, often a misplaced { or }, which then causes the compiler to parse subsequent code as if there were a nested function inside the errant { or outside a misplaced }. Or you might simply have botched the syntax so completely that the compiler can't even begin to guess what was intended, and a nested function was simply its best guess.


WorkoutsDetailViewController.title = [NSString stringWithFormat:@"X@", [workoutsArray objectAtIndex:.row]];

This statement looks dubious. Enlarged, with red hilites for the most dubious parts:
WorkoutsDetailViewController.title = [NSString stringWithFormat:@"X@", [workoutsArray objectAtIndex:.row]];

0. WorkoutsDetailViewController is a class name, not an ivar name, according to your code above this line that calls alloc on it. It's improbable this class has a title property or struct/union member (assuming it is a class).
1. There is no formatting specifier in the string "X@". If you meant "%@", you need to change it.
2. The .row has nothing preceding the dot to act as an object whose row property is used, or as a struct/union whose row member is used.


NSInteger row - [indexPath row];

It's difficult to tell what this is intended to mean. My guess is assignment. Again, enlarged to show detail, with red hilites on most dubious parts.


Frankly, I think you need to use a bigger font in Xcode. Every one of the red hilites is something that looks similar to something it isn't, or might be too small to notice for the inexperienced eye.

firewood
Feb 1, 2011, 01:12 AM
Check all your brackets, braces and parenthesis. Starting from the very beginning of the entire .m file. Make sure they all pair up. Most likely, somewhere you have one missing or badly misplaced.

geiger10d
Feb 1, 2011, 07:16 AM
Insufficient context.

1. Provide the entire method or function, not just an isolated fragment.

2. Identify exactly which line the error message is referring to.

The "nested functions" error message usually results from a completely unrelated and possibly far distant syntax error, often a misplaced { or }, which then causes the compiler to parse subsequent code as if there were a nested function inside the errant { or outside a misplaced }. Or you might simply have botched the syntax so completely that the compiler can't even begin to guess what was intended, and a nested function was simply its best guess.


WorkoutsDetailViewController.title = [NSString stringWithFormat:@"X@", [workoutsArray objectAtIndex:.row]];

This statement looks dubious. Enlarged, with red hilites for the most dubious parts:
WorkoutsDetailViewController.title = [NSString stringWithFormat:@"X@", [workoutsArray objectAtIndex:.row]];

0. WorkoutsDetailViewController is a class name, not an ivar name, according to your code above this line that calls alloc on it. It's improbable this class has a title property or struct/union member (assuming it is a class).
1. There is no formatting specifier in the string "X@". If you meant "%@", you need to change it.
2. The .row has nothing preceding the dot to act as an object whose row property is used, or as a struct/union whose row member is used.


NSInteger row - [indexPath row];

It's difficult to tell what this is intended to mean. My guess is assignment. Again, enlarged to show detail, with red hilites on most dubious parts.


Frankly, I think you need to use a bigger font in Xcode. Every one of the red hilites is something that looks similar to something it isn't, or might be too small to notice for the inexperienced eye.


#import "WorkoutsTableViewController.h"
#import "WorkoutsDetailViewController.h"
#import "iScheduleFitnessAppDelegate.h"


@implementation WorkoutsTableViewController
@synthesize workoutsArray;
@synthesize workoutsDetailViewController;

#pragma mark -
#pragma mark Initialization




#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad {
[super viewDidLoad];
self.title =NSLocalizedString(@"Workouts", @"Body Categories");
NSMutableArray *array = [[NSArray alloc] initWithObjects:@"Leg Workouts", @"Chest Workouts", @"Back Workouts", @"Shoulder Workouts", @" Bicep Workouts", @" Tricep Workouts", @"Ab Workouts", nil];
self.workoutsArray = array;
[array release];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}




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


#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}


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


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSUInteger row = [indexPath row];
cell.text = [workoutsArray objectAtIndex:row];
return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/


#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
NSInteger row - [indexPath row];
if (self.workoutsDetailViewController = nil) {
WorkoutsDetailViewController *aWorkoutDetail = [[WorkoutsDetailViewController alloc] initWithNibName:@"WorkoutsDetailView" bundle:nil];
self.workoutsDetailViewController = aWorkoutDetail;
[aWorkoutDetail release];
}
WorkoutsDetailViewController.title = [NSString stringWithFormat:@"X@", [workoutsArray objectAtIndex:.row]];
iScheduleFitnessAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.workoutsNavController pushViewController:workoutsDetailViewController animated:YES];
}
#pragma mark -
#pragma mark Memory management
//*
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}



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


@end

chown33
Feb 1, 2011, 10:14 AM
You haven't posted the headers that are imported.
#import "WorkoutsTableViewController.h"
#import "WorkoutsDetailViewController.h"
#import "iScheduleFitnessAppDelegate.h"

If there's an extra { in one of them, especially the last one imported, then it could cause a nested function error.


You also haven't identified exactly which line the error is on.
Please post the actual error message.
Please identify the line number where it occurs.


And please post your code inside Code tags. It's that little # icon in the "toolbar" of the posting text-area.


Finally, repeated postings of the same code in multiple threads won't help anyone solve the problem or produce an answer any faster. The opposite is more probable: I had to read each of the multiple posts to see if it was the same.

admanimal
Feb 1, 2011, 10:32 AM
All of chown's advice is very good.

But to get to the point, the error is almost certainly caused by this line:


NSInteger row - [indexPath row];


which obviously should be this:


NSInteger row = [indexPath row];


This is a trivial syntax error that you need to learn to identify (or avoid in the first place) in your sleep. Unfortunately the only sense the compiler can make of the misplaced - is that it thinks you're trying to define a new method (i.e. - (void)someMethodName) inside of another method, which is where the nested function error comes from.

geiger10d
Feb 1, 2011, 04:33 PM
ok i got it thanks so much