Re: make connections without InterfaceBuilder
Re: make connections without InterfaceBuilder
- Subject: Re: make connections without InterfaceBuilder
- From: Roland King <email@hidden>
- Date: Tue, 9 Feb 2010 20:36:48 +0800
No sorry this just won't work. Just because you give a button a given label in interface builder, that doesn't relate in any way to the instance variable in your code of the same name, that unfortunately is where the click-drag comes in, you connect the button at that point to the IBOutlet. When the NIB is unarchived all the objects are created, but only those things you have hooked up with Interface Builder are actually set to variables in your code.
There is a way to do it the way you're trying to do it, but it's impossibly hard. You'd need to make the NIB, give each element on it a unique tag (not name, there's a tag field there too), then you have to load the NIB yourself from the bundle, which will give you all the top-level objects in it. Then you iterate them, look for your tags and set your instance variables to those objects. ie you do the last bit you cannot do in Interface Builder, in code.
I believe you asked a similar question to this a couple of weeks ago in the Cocoa forums and it was suggested there that you create the user interfaces entirely in code and just don't bother with interface builder, and I think someone pointed you to one or more examples in the iPhone documentation where this is done that way. It's a lot easier with iPhone than OSX, people often choose to build their interfaces in code. If you're using Interface Builder to get the layout designed, you can still do this, get it designed in IB, then take down the positions and sizes and types of all the widgets and then create them in your code at those places, and hook them up to each other, that's all interface builder is doing anyway really.
I can't imagine how hard it must be to try to write code when you are blind, especially when one of the tools is very graphical in nature. I think by trying to use this tool when you're able to make the widgets but not the connections, you're making it very hard for yourself, if not impossible.
On 09-Feb-2010, at 7:49 PM, Ian Jackson wrote:
>
> On 9/02/2010, at 5:09 PM, Fritz Anderson wrote:
>
>> On 8 Feb 2010, at 10:03 PM, Jonathan Chacón wrote:
>>
>>> - (void)awakeFromNib:(id)sender {
>>> [boton setTarget:self];
>>> [boton setAction:@selector(botonClick:)];
>>> }
>>
>> You mean awakeFromNib (no arguments) not awakeFromNib: (one argument). They name completely different methods, and awakeFromNib is the one the NIB-loading system calls.
>>
>> — F
>>
>> _______________________________________________
>> Do not post admin requests to the list. They will be ignored.
>> Xcode-users mailing list (email@hidden)
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
> I'd be interested to hear if you succeed with this. Even with the IBOutlet for the boton declared, there is still nothing to say that you are referring to the button that you have created in IB. For example, in the case where the connections are made by control dragging, you could create two buttons called buttonOne, and buttonTwo.
>
> Then in Xcode, create just one outlet, which would be called ButtonOne. And have an action do [buttonOne setEnabled:NO];
>
> Then, back in IB if you connect ButtonTwo to the AppDelegate (both ways), when you run the app, buttonOne does not respond to clicks (despite the outlet sharing the name), or change when buttonTwo is clicked. However, buttonTwo works when you click it - setting itself to not enabled.
>
> In summary:
>
> [boton setTarget:self];
>
> is only going to work, if the app somehow knows that boton refers to the button which was called boton in IB. setAction: will only work when you already have a connection to the button in IB I believe (this appears to be true in practice).
>
> Ian. _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden