• 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: Is awakeFromNib REALLY first to run?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is awakeFromNib REALLY first to run?


  • Subject: Re: Is awakeFromNib REALLY first to run?
  • From: "John C. Randolph" <email@hidden>
  • Date: Fri, 29 Jun 2001 19:44:43 -0700

On Friday, June 29, 2001, at 07:29 PM, email@hidden wrote:

Hi all,

I've been playing around with Cocoa, trying to get through the Oreilly book, and I've come across something that doesn't seem right. Although the Oreilly book says that awakeFromNib is always run first. However, in this code example derived from the books Very Simple Table, it appears that numberOfRowsInTableView gets run at least a couple of times. The result is that until I manually resize my table, I can't access the other items in my table (i.e. vertical scroll is inactive).

So what am I missing (other than a complete understanding of Objective C!)?

- (void) awakeFromNib
{
int index;

myArray = [[NSMutableArray alloc] init];

for (index = 0; index < 30; ++index)
{
NSDecimalNumber *myNumber = [NSDecimalNumber numberWithInt:index];
[myArray addObject: myNumber];
[myArray retain];

Well, here's one mistake. Do you really want to retain myArray 30 times? (Actually, you don't need to -retain it at all, since +alloc gives it to you with a retain count of one.

As for -awakeFromNib, I don't think we've ever been promised that it gets run only *once*, so you should take care not to leak memory in the event that it gets called multiple times. Same with +initialize and -init.

-jcr


"This is not a book to be tossed aside lightly. Rather, it should be hurled with great force." -Dorothy Parker


References: 
 >Is awakeFromNib REALLY first to run? (From: email@hidden)

  • Prev by Date: Is awakeFromNib REALLY first to run?
  • Next by Date: Re: Apple Events in Cocoa
  • Previous by thread: Is awakeFromNib REALLY first to run?
  • Next by thread: Re: Is awakeFromNib REALLY first to run?
  • Index(es):
    • Date
    • Thread