On 05/05/2011, at 10:52 AM, Martin Batholdy wrote:

> - (void)updateView {
>       [content removeObjectAtIndex:1];
>       [table reloadData];
>       [table deselectAll:self];
> }
> 
> 
> and when the menuitem is pressed the following is invoked (in a different 
> class):
> 
> 
> prefShow = [Preferences sharedPrefsWindowController];       ( <- this is my 
> singleton)
> [prefShow updateView];
> 
> 
> 
> 
> Everything works fine – the updateView method is called and the 
> NSMutableArray (content) is also updated properly.
> However nothing changes in the table. 
> [table reloadData] seems to have no effect.


Have you checked to see whether removeObjectAtIndex:1 actually succeeds? If the 
index is out of bounds, an exception will be thrown and -reloadData will never 
be reached. You can easily check that in the debugger. It looks suspicious that 
you are hard-coding an index value for an array whose contents are variable.

If you always want to remove the first object, the correct index is 0, but even 
that will fail if the array is empty. If you always want to remove the last 
object, use [NSArray lastObject], which will return nil if the array is empty. 
In general, naming a method -updateView that also removes an object from 
<content> is setting yourself up for buggy behaviour. Either separate out the 
removal from the update, or else rename the method so it's clear what it 
actually does.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to