• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: update a tableView from a different class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: update a tableView from a different class


  • Subject: Re: update a tableView from a different class
  • From: Graham Cox <email@hidden>
  • Date: Thu, 05 May 2011 11:35:06 +1000

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: update a tableView from a different class
      • From: Martin Batholdy <email@hidden>
References: 
 >update a tableView from a different class (From: Martin Batholdy <email@hidden>)

  • Prev by Date: Re: update a tableView from a different class
  • Next by Date: Re: update a tableView from a different class
  • Previous by thread: Re: update a tableView from a different class
  • Next by thread: Re: update a tableView from a different class
  • Index(es):
    • Date
    • Thread