awakeFromNib and addTarget

19 views
Skip to first unread message

Michael Koppelman

unread,
Aug 10, 2010, 9:15:34 PM8/10/10
to iphonedevmn
I'm confused (again).

Apple's docs say, "Messages to other objects can be sent safely from
within an awakeFromNib method."

In my awakeFromNib method I have the following lines:

[textToolButton addTarget:self action:@selector(newTextField)
forControlEvents:UIControlEventTouchUpInside];
NSLog( @"Have %i actions.", [[textToolButton actionsForTarget:self
forControlEvent:UIControlEventTouchUpInside] count] );

The second line prints out:

2010-08-10 20:04:51.233 Notebook[594:207] Have 0 actions.

If I put the exact same lines in code that executes later, it works as
expected. Apple's docs also say, "Typically, you implement
awakeFromNib for objects that require additional set up that cannot be
done at design time. For example, you might use this method to
customize the default configuration of any controls to match user
preferences or the values in other controls."

That is exactly what I'm trying to do. textToolButton is an object in
the nib. It seems like I am using awakeFromNib exactly as it is
intended to be used. Yet it doesn't work. Does anyone know why?

Thanks!
M.

Paul Cantrell

unread,
Aug 11, 2010, 12:06:05 AM8/11/10
to iphon...@googlegroups.com
Just a sanity check, but make sure textToolButton is not nil at that point.

P

> --
> You received this message because you are subscribed to the Google Groups "iphonedevmn" group.
> To post to this group, send email to iphon...@googlegroups.com.
> To unsubscribe from this group, send email to iphonedevmn...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/iphonedevmn?hl=en.
>
>

Michael Koppelman

unread,
Aug 11, 2010, 11:15:07 AM8/11/10
to iphonedevmn
It is nil. I meant to check that. My question still stands, though --
why is it nil? Apple's docs lead me to believe everything should be
fully initialized by the time awakeFromNib is called. It says, "After
all objects have been instantiated and initialized, the nib-loading
code reestablishes the outlet and action connections for all of those
objects. It then calls the awakeFromNib method of the objects."

Time for plan B I guess.

Thanks!
M.

Michael Koppelman

unread,
Aug 11, 2010, 11:25:42 AM8/11/10
to iphonedevmn
No biggie, I'll just use viewDidLoad, which works fine, thanks!

M.

On Aug 11, 10:15 am, Michael Koppelman <michael.koppel...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages