-(id)initWithNib:(NSString*)nibName frame:(CGRect)frame{
if(self = [super initWithFrame:frame]){
self = [[[NSBundle mainBundle] loadNibNamed:@"UpdateView"
owner:self options:nil] objectAtIndex:0]; // This looks a little strange
// But this is what I found
}
return self;
}
My view appears when called, with all of its controls. The controls
behave expected when clicked, except the textview, which never takes
focus when clicked, and thus the keyboard never appears. All of the
controls were setup as IBOutlets and as properties of the sybclass, but
when I try to reference any of them using the dot syntax, my application
crashes.
Here's what I'm trying to do:
I have a grouped tableview. When the user clicks the compose button,
this view should appear by sliding down from the top of the screen. I
use an animation to change its height from 0 to about 220px. This much
works just fine. I just can't communicate with any of the controls and
my textview does not does not get focus after the view appears.
Any ideas or sample code on how this should be done are most appreciated.
Thanks
> I found a couple of examples on the internet on how to do this, but I'm
> still having trouble communicating with controls on my UIVew. Actually,
> I have a subclass of UIView (No view controller), built in IB that
> contains several controls, a switch, a couple of buttons a textview and
> a couple of labels. I initialize my subclass like this:
>
> -(id)initWithNib:(NSString*)nibName frame:(CGRect)frame{
>
> if(self = [super initWithFrame:frame]){
> self = [[[NSBundle mainBundle] loadNibNamed:@"UpdateView"
> owner:self options:nil] objectAtIndex:0]; // This looks a little strange
> // But this is what I found
>
> }
> return self;
> }
Usually the class that wants to load the view would do the nib loading,
and the UIView would be loaded from the nib. I'm not exactly sure what
the effects of doing it this way would be but I'd expect problems-- not
least being that the subview controls might not work because they might
be targeting the wrong object.
> My view appears when called, with all of its controls. The controls
> behave expected when clicked, except the textview, which never takes
> focus when clicked, and thus the keyboard never appears. All of the
> controls were setup as IBOutlets and as properties of the sybclass, but
> when I try to reference any of them using the dot syntax, my application
> crashes.
Did you connect "File's Owner" to those subviews in Interface Builder?
It sounds like you missed a step, so your IBOutlets are not actually
connected to anything.
--
Tom "Tom" Harrington
Independent Mac OS X developer since 2002
http://www.atomicbird.com/
Yes, I did connect File's Owner to them. But after playing with it for a
while, I decided to use a uiviewcontroller to manage the view. This
seems to work better in that I can reference the various controls on the
view. But after I animate the view, the uitextview does not have focus,
so the keyboard does not display as I would expect. The view is created
with a height of 0, so it initially has no onscreen appearance. When I
animate the view, I give it a height which makes it appear to slide down
from the top of the screen. I use a delegate method to let me know when
the animation is done, at which point I call [textview
becomefirstresponder], but I don't get the keyboard until I tap the
textview. So that's my last issue, if you can help with that.