Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-19-2011, 02:08 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 3
medlewood is on a distinguished road
Default Pass cellForRowAtIndexPath to appDelegate?

Hi! This is my first post here, really hoping someone can help as I have searched for ages trying to solve this (I am a relative noob to Obj-C), anyway heres the situation...

I have an application with two table views:

The first view has an array of 'todo' items. Each item/row has a button, when clicked it updates the sqlite db, marking an item as complete (status =1);

The second view has an array of these completed 'todo' items;

Now this is working except that in the first tableview I can't seem to bind the cell indexpath.row to the primarykey for the item in that cell when the button is clicked (indexpath starts at 0, primarykey starts at 1).

Any advice is greatly appreciated... I can post some code if that would help?

Many thanks!

Code:

RootViewController.m

Code:
// called when a user presses the button to alter the status

- (void)updateStatus:(id)sender { 
	
	NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)[sender superview]];
	NSInteger row = indexPath.row;
    NSLog(@"The row is %i", row); 
		
	todoAppDelegate *appDelegate = (todoAppDelegate *)[[UIApplication sharedApplication] delegate];
	Todo *td = [appDelegate.todos objectAtIndex:indexPath.row];

	if (td.status == 0) {		
		[td updateStatus:1];					
		NSLog(@"Status is %i",td.status);
	}
	else {
		[td updateStatus:0];
		NSLog(@"Status is %i",td.status);
	}
	}

todoAppDelegate.m

Code:
-(void)updateItemAtIndexPath:(NSIndexPath *)path {
	
	Todo *td = (Todo *)[todos objectAtIndex:path.row];	
	int ret;
	
	const char *sql = "update todo set complete = ? where pk= ?;";
	
	if (dehydrate_statment == nil)
	{ // build update statement
		if ((ret=sqlite3_prepare_v2(database, sql, -1, &dehydrate_statment, NULL))!=SQLITE_OK)
		{
			NSAssert1(0, @"Error building statement to update todos [%s]", sqlite3_errmsg(database));
		}
	}
	
	// bind values to statement

	NSInteger p = td.primaryKey;
	NSLog(@"tdprimaryKey is %i",td.primaryKey);
	sqlite3_bind_int(dehydrate_statment, 2, p);

	NSInteger s = td.status;
	sqlite3_bind_int(dehydrate_statment, 1, s);
	
	// now execute sql statement
	if ((ret=sqlite3_step(dehydrate_statment)) != SQLITE_DONE)
	{
		NSAssert1(0, @"Error updating values [%s]", sqlite3_errmsg(database));
	}
	
	// now reset bound statement to original state
	sqlite3_reset(dehydrate_statment);
	
	NSLog(@"updateItemAtIndexPath called");

}


Problem here is I cant get the indexPath.row to match the primaryKey and I can't pass the indexPath.row to the todoAppDelegate...

Last edited by medlewood; 04-20-2011 at 08:10 AM. Reason: Added code
medlewood is offline   Reply With Quote
Old 04-19-2011, 02:47 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Posting code almost always helps. Please do so.
smithdale87 is offline   Reply With Quote
Old 04-24-2011, 01:30 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 3
medlewood is on a distinguished road
Default

Thanks. Updated with code, can provide more if necessary! Thanks again...
medlewood is offline   Reply With Quote
Reply

Bookmarks

Tags
indexpath, sqlite, uitableview cell

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 350
14 members and 336 guests
dansparrow, dre, ilmman, LezB44, lorrettaui53, Nobbsy, Objective Zero, oztemel, pbart, samdanielblr, shagor012, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0