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 12-11-2010, 11:51 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 15
Starhopper108 is on a distinguished road
Default tableview reloadData crash

I'm making a simple app that retrieves data from a sqlite3 database and places it into a table view. I've set up an add function that pulls up a modal view controller and lets you add new data to the database, but how do I make the table view refresh when the modal view controller is dismissed? I've tried reloadData in viewWillAppear and many other methods. The new data does get added to the table view, and I can scroll around, but once I scroll down to where the new cell is, the application crashes. When I reopen the application, the new entry is in the table view and it runs without any errors. I'm using the most updated version of the SDK currently.
Starhopper108 is offline   Reply With Quote
Old 12-11-2010, 01:13 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Starhopper108 View Post
I'm making a simple app that retrieves data from a sqlite3 database and places it into a table view. I've set up an add function that pulls up a modal view controller and lets you add new data to the database, but how do I make the table view refresh when the modal view controller is dismissed? I've tried reloadData in viewWillAppear and many other methods. The new data does get added to the table view, and I can scroll around, but once I scroll down to where the new cell is, the application crashes. When I reopen the application, the new entry is in the table view and it runs without any errors. I'm using the most updated version of the SDK currently.
You have to be careful that your table view's data source returns the correct number of rows and sections, and serves up data that matches the counts you provide. If there's a mismatch, you crash. Look at the specific error code to figure out what's going wrong.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 12-19-2010, 12:17 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 15
Starhopper108 is on a distinguished road
Default

I'm relatively new to this, and the debug console is giving an error that says "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString pokemonName]: unrecognized selector sent to instance 0x4bb0b40'". I'm having trouble understanding what an NSCFString is
Starhopper108 is offline   Reply With Quote
Old 12-19-2010, 12:20 PM   #4 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Whats your declaration for pokemonName? And how is it used in your tableView? I am assuming that the pokemonName is a string.
Quote:
Originally Posted by Starhopper108 View Post
I'm relatively new to this, and the debug console is giving an error that says "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString pokemonName]: unrecognized selector sent to instance 0x4bb0b40'". I'm having trouble understanding what an NSCFString is
iSDK is offline   Reply With Quote
Old 12-19-2010, 12:32 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 15
Starhopper108 is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
Whats your declaration for pokemonName? And how is it used in your tableView? I am assuming that the pokemonName is a string.
I have it declared in the pokemon object header file as, yes, an NSString. I'm taking the text from a textField where you input the name of a new entry and placing it in an 'insert into' sql statement that I convert into a UTF8String, and then I add the saved name to the NSMutableArray that the tableView gets its data from.
Starhopper108 is offline   Reply With Quote
Old 12-19-2010, 12:36 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Starhopper108 View Post
I'm relatively new to this, and the debug console is giving an error that says "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString pokemonName]: unrecognized selector sent to instance 0x4bb0b40'". I'm having trouble understanding what an NSCFString is
Post the code that's generating the error, as well as the header for the class that includes the "pokemonName" property.

There are 2 likely causes of this error:
  1. You've got an error in your code and are trying to ask a string object for a "pokemonName" property.
  2. You have an object that's over-released, and that memory location is being replaced with a new object of a different type.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 12-19-2010, 12:50 PM   #7 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 15
Starhopper108 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Post the code that's generating the error, as well as the header for the class that includes the "pokemonName" property.

There are 2 likely causes of this error:
  1. You've got an error in your code and are trying to ask a string object for a "pokemonName" property.
  2. You have an object that's over-released, and that memory location is being replaced with a new object of a different type.
Here's the object's header file:
Code:
@interface Pokemon : NSObject {
	NSString *pokemonName, *pokemonType1, *pokemonType2, *number;
}
@property (nonatomic, retain) NSString *pokemonName, *pokemonType1, *pokemonType2, *number;


-(id)initWithName:(NSString *)na type1:(NSString *)t1 type2:(NSString *)t2 number:(NSString *)n;

@end
and this is the save method under a viewController of a modal view:

Code:
-(IBAction)save {
	databaseName = @"pokemon.db";
	NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDir = [documentPaths objectAtIndex:0];
	databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
	NSString *savedNumber = numberField.text;
	NSString *savedType1 = type1Field.text;
	NSString *savedType2 = type2Field.text;
	NSString *savedName = nameField.text;
	sqlite3 *database;
	if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
		NSString *stmt = [NSString stringWithFormat:@"insert into kanto (number, type1, type2, name) values ('%@', '%@', '%@', '%@');", savedNumber, savedType1, savedType2, savedName];
		const char *sqlStatement = [stmt UTF8String];
		sqlite3_stmt *compiledStatement;
		sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
		sqlite3_step(compiledStatement);
		
		sqlite3_finalize(compiledStatement);
	}
	sqlite3_close(database);
	
	PokemonSQLAppDelegate *delegate = (PokemonSQLAppDelegate *)[[UIApplication sharedApplication] delegate];
	[delegate.pokemon addObject:savedName];
	[delegate.pokemon addObject:savedType1];
	[delegate.pokemon addObject:savedType2];
	[delegate.pokemon addObject:savedNumber];
	[self dismissModalViewControllerAnimated:YES];
}
I then have the tableView reloadData in the root view controller under viewWillAppear
Starhopper108 is offline   Reply With Quote
Old 12-19-2010, 12:58 PM   #8 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 327
thomashw is on a distinguished road
Default

I don't think the error is occurring in that method, since I can't see pokemonName used anywhere.

Try setting breakpoints to narrow down where the error is occurring and then post the method it's occurring in.
thomashw is offline   Reply With Quote
Reply

Bookmarks

Tags
crash, reloaddata, sqlite3, table view

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: 380
7 members and 373 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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