15 Jan 2009, 03:00
Agustin_arroyo_pragsmall

AGUSTIN ARROYO (25 posts)

When adding a new ingredient pressing the right editButtonItem(Done) the New Ingredient is added to the db table, but the ingredients table view is not updated, however when pressing the Done button from the keyboard the table view is updated correctly.

I tried using [tableView reloadData]; but it didn’t work.

Hope you can give me some guidance.

Thanks

15 Jan 2009, 12:16
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi Agustin,

Did you download the code from the screencast? I think this is a known bug and has been fixed.

You can grab the code here;

http://www.pragprog.com/screencasts/v-bdiphone/source_code

good luck!

15 Jan 2009, 17:53
Agustin_arroyo_pragsmall

AGUSTIN ARROYO (25 posts)

Hi Bill,

Thanks for your quick response.

I did download it, opened it an compiled it.

If you have the chance to Build and Go your code, it actually does behaves the same.

When adding a new ingredient pressing the right editButtonItem(Done) the New Ingredient is added to the db table, but the ingredients table view is not updated, however when pressing the Done button from the keyboard the table view is updated correctly.

Hope you have a change to find the bug.

I really appreciate your help.

Agustin.

15 Jan 2009, 23:12
Agustin_arroyo_pragsmall

AGUSTIN ARROYO (25 posts)

Bill,

When adding a new ingredient (the one that is not being displayed) and pressing Edit again. I also get the error.

(gdb) continue objc[416]: objc_exception_throw failed Program received signal: “EXC_BAD_INSTRUCTION”.

There most be something wrong with the implementation of the editButtonItem(Done);

Hope to hear from you.

Thanks.

15 Jan 2009, 23:32
Agustin_arroyo_pragsmall

AGUSTIN ARROYO (25 posts)

Bill,

This Topic should be related to Topic Crash deleting ingredient.

I have been simulating with iPhone OS 2.1 & 2.2 and it does behave different. With OS 2.1 the table view is reloaded after pressing the Edit Button. With OS 2.2 after adding and ingredient an pressing the Edit Button I also get the error:

* Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update must be equal to the number of rows contained in that section before the update, plus or minus the number of rows added or removed from that section.**

17 Jan 2009, 01:38
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hm,

Sound like a bug in my code exposed by the upgrade to 2.2. I will try to dig into it tomorrow and see if I can get you a fix.

Thanks for taking the time to report the problem!

19 Jan 2009, 04:18
Agustin_arroyo_pragsmall

AGUSTIN ARROYO (25 posts)

Thanks Bill,

I’ve been digging it my self with out success.

Too novice.

19 Jan 2009, 22:42
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi,

I downloaded the sample code, made no change clicked Build and Go, and it just worked. I’m able to add ingredients without problems. No messages on the console and only warnings about the nib files, like this;

bq. warning: UIScrollView’s ‘Bounce Zoom’ option will be ignored on iPhone OS versions prior to 2.1

Which can be safely ignored for this discussion.

Could you try downloading a fresh copy of the source code and running a ‘diff’ between the two directories?

Put the code that is not working and the fresh copy of the sample code into a directory. I’ll refer to it as ‘foo’.

Open Terminal and cd into ‘foo’.

Type ‘opendiff yourcode newcode’ on the command line and look at all the difference between the projects.

Also I am on Xcode 3.1.2, iPhone OS 2.2.

Good luck and let me know when you figure it out.

19 Jan 2009, 16:15
Agustin_arroyo_pragsmall

AGUSTIN ARROYO (25 posts)

Bill, I am running the most recent code. To emulate the same error, try the following sequence: 1 Click on Cookie 2 Hit Edit 3 Add a new Ingredient 4 Type Chocolate 5 Hit Done on the top navigation bar NOT the Keyboard 6 Chocolate is not displayed until pressing All recipes and pressing Cookie Again if you press Edit after adding the New Ingredient then you would get the error: *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update must be equal to the number of rows contained in that section before the update, plus or minus the number of rows added or removed from that section.’

20 Jan 2009, 03:13
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi,

I do not get the error message. Strange.

However I do get the same ‘new ingredient does not show up problem’.

The reason that the new ingredient does not show up is because I used the viewWillAppear: method on the IngredientsController to reload the table view’s data. If you switch that to viewDidAppear: then it will probably work more like it should.

Basically what is happening…

1 you click ‘done’ in the nav bar 2 the view animates out and the IngredientsController’s view animates in 3 the viewWillAppear: method is sent to the IngredientsController 4 the reloadData message is sent to the table view (of the IngredientsController) 5 the text field notices that its been moved off screen so it resigns first responder 6 the NewIngredientsViewController gets the text field delegate method ‘textFieldDidEndEditing:’ 7 the NewIngredientsViewController adds the ingredient to the data

Since the reloadData method is called before the data is added the soon to be old data is displayed instead of the new data. Switching that method to ‘viewDidAppear:’ will delay the call to reload data until the new data is in the list.

Hope this helps and I’ll look at how to best fix up the code as soon as I can.

Sorry for the confusion!

20 Jan 2009, 04:57
Agustin_arroyo_pragsmall

AGUSTIN ARROYO (25 posts)

Bill, Thanks for your effort. Finally I have it working fine. I left both methods:

  • (void)viewWillAppear:(BOOL)animated { [tableView reloadData]; }

  • (void)viewDidAppear:(BOOL)animated { [tableView reloadData]; }

It works much like it should. May be too much code. I found out that iPhone SDK comes with FileMerge (search for it at Spotlight), instead of using opendiff from the Terminal.

  You must be logged in to comment