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

taleryfilms

macrumors newbie
Original poster
Aug 18, 2010
3
0
Hey guys this is code for a UiTableview in IPHONE SDK xcode. I need to know how to fix these errors. The highlight words are the errors.

here are the error messages:
error: 'addrowtotableview' undeclared (first use in this function)

error: expected ';' before '{' token


Code:
#import "tablearchiveAppDelegate.h"

@implementation tablearchiveAppDelegate

@synthesize window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    NSArray *archivedarray = [NSKeyedUnarchiver unarchiveObjectWithFile:[self DataFilePath]];
	if (archivedarray == nil) {
		
		data = [[NSMutableArray alloc] init];
		
	}else {
		data = [[NSMutableArray alloc] initWithArray:archivedarray];
	
	
	// Override point for customization after application launch
    [window makeKeyAndVisible];
}

[COLOR="Red"] - (IBAction)addrowtotableview [/COLOR]
[COLOR="DeepSkyBlue"]{	
		[data addObject:tableCellText.text];
		[self savedata];
		[maintableview reloadData];[/COLOR]
	}
	
	- (IBAction)edittable {

		UIBarButton *leftitem;
		[maintableview setEditing:!maintableview.editing animated:YES
		if (maintableview.editing) {
			leftitem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(edittable)];
			
		} else {
			
			leftitem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(edittable)];
	}
		NavItem.rightBarButtonItem = leftitem;
		[self savedata];
		[maintableview reloadData];
	
	- (IBAction)endtext {
	}
	
- (NSInteger)NumberOfSectionsInTableView:(UITableView *)tableview {
	
	return 1;
}
- (NSInteger)tableview:(UITableView *)tableview NumberOfRowsInSection:(NSInteger)section 
{
	
	return [data count];
}
	
- (UITableViewCell *)tableview:(UITableView *)tableview cellRowAtindexPath:(NSIndexPath *)indexpath {

	UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:@"Cell"];
	if (cell == nil) {
	
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];
	}

	cell.textLabel.text = [data objectAtIndex:indexpath.row];
	
	return cell; 
}

- (NSString *)datafilepath {
	
	NSString *DataFilePath;
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentdirectory = [paths objectAtIndex: 0];
	DataFilePath = [[documentdirectory stringByAppendingPathComponent:@"applicationdata.plist"] retain];
	return DataFilePath;
	
	- (void)saveData {
		[NSKeyedArchiver archiveRootObject:[data copy] toFile:[self DataFilePath]];
		
		-(void)tableview:(UITab *)tableview commiteditingstlye:(UITableViewCellEditingStyle)editingstyle forrowatindexpath:(NSIndexPath *)indexpath {
			[data removeObjectAtIndex:indexpath.row];
			[tableview deleteRowsAtIndexPaths:[NSArray arraywithobject:indexpath]
							 withRowAnimation:UITableViewRowAnimationLeft];

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


@end
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
error: 'addrowtotableview' undeclared (first use in this function)

Hey guys this is code for a UiTableview in IPHONE SDK xcode.
Then it should go in the iPhone & iPad Programming Forum.

https://forums.macrumors.com/forums/135/

I've asked the moderators to move it.


Answer is hilited in BLUE below.
error: 'addrowtotableview' undeclared (first use in this function)

error: expected ';' before '{' token


Code:
#import "tablearchiveAppDelegate.h"

@implementation tablearchiveAppDelegate

@synthesize window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    NSArray *archivedarray = [NSKeyedUnarchiver unarchiveObjectWithFile:[self DataFilePath]];
	if (archivedarray == nil) {
		
		data = [[NSMutableArray alloc] init];
		
	}else {
		data = [[NSMutableArray alloc] initWithArray:archivedarray];
[COLOR="blue"]You're missing a } here...[/COLOR]
	
	// Override point for customization after application launch
    [window makeKeyAndVisible];
}  
[COLOR="blue"]... so this } looks to the compiler like it closes the else block[/COLOR]

[COLOR="blue"]...and everything below looks like statements, which don't parse.
[/COLOR]
[COLOR="Red"] - (IBAction)addrowtotableview [/COLOR]
[COLOR="DeepSkyBlue"]{	
		[data addObject:tableCellText.text];
		[self savedata];
		[maintableview reloadData];[/COLOR]
	}
	
	- (IBAction)edittable {

		UIBarButton *leftitem;
		[maintableview setEditing:!maintableview.editing animated:YES
		if (maintableview.editing) {
			leftitem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(edittable)];
			
		} else {
			
			leftitem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(edittable)];
	}
		NavItem.rightBarButtonItem = leftitem;
		[self savedata];
		[maintableview reloadData];
	
	- (IBAction)endtext {
	}
	
- (NSInteger)NumberOfSectionsInTableView:(UITableView *)tableview {
	
	return 1;
}
- (NSInteger)tableview:(UITableView *)tableview NumberOfRowsInSection:(NSInteger)section 
{
	
	return [data count];
}
	
- (UITableViewCell *)tableview:(UITableView *)tableview cellRowAtindexPath:(NSIndexPath *)indexpath {

	UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:@"Cell"];
	if (cell == nil) {
	
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];
	}

	cell.textLabel.text = [data objectAtIndex:indexpath.row];
	
	return cell; 
}

- (NSString *)datafilepath {
	
	NSString *DataFilePath;
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentdirectory = [paths objectAtIndex: 0];
	DataFilePath = [[documentdirectory stringByAppendingPathComponent:@"applicationdata.plist"] retain];
	return DataFilePath;
	
	- (void)saveData {
		[NSKeyedArchiver archiveRootObject:[data copy] toFile:[self DataFilePath]];
		
		-(void)tableview:(UITab *)tableview commiteditingstlye:(UITableViewCellEditingStyle)editingstyle forrowatindexpath:(NSIndexPath *)indexpath {
			[data removeObjectAtIndex:indexpath.row];
			[tableview deleteRowsAtIndexPaths:[NSArray arraywithobject:indexpath]
							 withRowAnimation:UITableViewRowAnimationLeft];

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


@end
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
Hey man. You might want to start at the beginning. Are you following a book or online course?

Your braces aren't balanced. They teach that on day one of iPhone coding school.

Ew, and you cross-posted. And you probably registered today to ask this question.

This is not how you learn to program.
 

taleryfilms

macrumors newbie
Original poster
Aug 18, 2010
3
0
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.