Re: Connecting a button to MyView zeros integers
Re: Connecting a button to MyView zeros integers
- Subject: Re: Connecting a button to MyView zeros integers
- From: Roland King <email@hidden>
- Date: Thu, 12 Feb 2015 13:56:32 +0800
> On 12 Feb 2015, at 13:36, N!K <email@hidden> wrote:
>
> Control-clicking the button in .xib does show the outlet panel but it does not list an IBAction, so it cannot connect to the IBAction entered into the MyView.h and .m files. Also, control-dragging from the button to MyView (in .xib, not in editor) sets up the position constraints. Control-dragging from the button to any icon does nothing.
>
Ctrl click the view, not the button. When you ctrl-click the view you will see the actions listed and you can drag BACK to the button. Or you can go find the ‘connections inspector’ (View->Utilities->Show Connections Inspector) panel for the button and drag ‘selector’ to the view you want to perform the action on and then you can select the action performed. Either way works, there’s probably a load more ways like the connections inspector on the view which you can probably drag the IBAction to whatever button you want.
>
> This Xcode_Overview example uses an implementation file, not AppDelegate. It does not add an empty object in IB.
>
> Xcode is not allowing connection to my MyView file. Insertion of - (IBAction)act:(id)sender { } occurs only in my AppDelegate, which of course responds to the button. Clicking the button in the View initiates the IBAction, which indicates that I’m following the instruction correctly. I do the same steps when I try it with my MyView file, which fails.
>
> Might this be a bug? Or a defective copy of Xcode? Has anyone observed the same behavior?
No somehow you are just flapping at it and failing. Not a bug, not a defective copy of Xcode.
Go to your view header file and type in the IBAction, you will then find it listed either on ctrl-click on the view (assuming you have the view in your NIB set to the right class, you do right, you did set the view class in IB) or by going to the connection inspector for the button and dragging the ‘selector’ to the view, when it will list only the IBActions.
>
> Nick
>
>
>
> On Feb 7, 2015, at 10:27 PM, Uli Kusterer <email@hidden <mailto:email@hidden>> wrote:
>
>> So quick to discount Stack Overflow. What they’re suggesting is simply how to create a new object and define a new outlet on it that points to an object in a quick way. Seems like a perfectly good answer to a problem to me, and my guess is the OP might not have quite matched it up to the right question. Without a link to the answer, it’s hard to tell.
>>
>> My guess is the OP is experiencing a common beginners’ confusion about how NIB files work and is creating a second object while all they want to do is really just hook something up to an existing object in the NIB, likely to File’s Owner. Creating a new object instead of using an existing one of course means that all ivars get new (likely default) values, which would be completely consistent with the observed behaviour of “everything going to 0”.
>>
>> Cheers,
>> -- Uli Kusterer
>> “The Witnesses of TeachText are everywhere...”
>> http://zathras.de <http://zathras.de/>
>>
>>> On 07 Feb 2015, at 03:43, Roland King <email@hidden> wrote:
>>>
>>> I have no idea what stackoverflow is suggesting here but it looks entirely wrong as usual for that junky site. You're just creating a standalone I referenced object.
>>>
>>> Right click your view in IB then wait a second and right click it again. I think it's right clicks. You will then get the outlet panel which is the grey HUD display with all the outlets and actions. You can drag connect to your buttons. There's some ctrl alt shift cmd combo which does this too but I never remember it. You can still connect view outlets as before, just that ctrl-drag was repurposed a couple of xcodes ago for auto layout so you have to work a little harder to get the inspector up.
>>>
>>>
>>>
>>>> On 7 Feb 2015, at 10:22, N!K <email@hidden> wrote:
>>>>
>>>>
>>>> I would like to connect a button to MyView class, but Xcode 6.1.1 only allows control-dragging a button to AppDelegate to create an IBAction. I have not encountered this previously. Looking for a workaround, I found this recommendation in a couple of Stack Overflow and other web pages as well as a YouTube video. It enables the button to work, but unfortunately it zeros all the integers in MyView.
>>>>
>>>> The recommendation is:
>>>> 1. Drag an empty Object from the IB library to the column of blue icons.
>>>> 2. Set its class to MyView.
>>>> 3. Control-drag from the button to MyView.m
>>>> 4. Fill in the name (“act”) in the popup.
>>>> This puts the IBAction template into MyView, ready to fill in.
>>>>
>>>> #import "MyView.h"
>>>>
>>>> @implementation MyView
>>>>
>>>> - (id)initWithCoder:(NSCoder *)aDecoder
>>>> {
>>>> self = [super initWithCoder:aDecoder];
>>>> if (self) {
>>>> iii=1000;
>>>> k=99;
>>>> }
>>>> return self;
>>>> }
>>>>
>>>> - (IBAction)act:(id)sender {
>>>> iii=iii+1;
>>>> NSLog(@" iba i= %i",iii);
>>>> }
>>>>
>>>>
>>>> In MyView.m, iii=1000 is initialized in initWithCoder. At the breakpoint after IBAction, iii is seen in both places to have the value 1, not 1001, by hovering. It was zeroed and then incremented after clicking on Button in the View. Similarly, k is initialized to 99 and then zeroed. Both are ivars in MyView.h.
>>>>
>>>> Clearly, zeroing all the integers is not acceptable. Can this approach be saved? Having the IBAction in MyView is desirable for directly relating its functions to the rest of MyView, rather than indirectly from AppDelegate. On the other hand, Xcode may have very good reasons – unknown to me – for restricting IBAction to AppDelegate. Maybe timing?
>>>>
>>>> Thanks in advance,
>>>>
>>>> Nick
>>>> __________
_______________________________________________
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