Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K

On Feb 11, 2015, at 9:56 PM, Roland King r...@rols.org wrote:

 
 On 12 Feb 2015, at 13:36, N!K pu56ucl...@alumni.purdue.edu 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. 

Thank you. This indeed works. This is  essentially an improvement over what I 
learned in Hillegas’ 3rd edition, which always worked.

So how have I been going astray? Well, things have changed since then. Your 
instruction above got me up to today’s relaxed rules.

1. Hillegas made a big point of dragging from the button, which doesn’t list 
the IBAction. So I never got as far as trying to drag from the view, which does 
have the IBAction in its list. This works.
2. The button’s list doesn’t have an IBAction in it, but it does have a 
selector. It didn’t occur to me to try dragging from that, and then the panel 
with the IBAction shows up. This works, too.
3. It’s no longer necessary to add an empty object icon, as Hillegas did in his 
example on pp.20-21.

On my original path, I was able to make  the current example – in Apple’s 
Xcode_Overview.pdf, 2014-03-10, pp 64-65 – work with MyView by adding an empty 
object icon. But this zeroed all my integers; not acceptable.

 
 
 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. 

Maybe this remains to be seen. Although the advice above works, my original 
request for help was based on my attempt to follow Apple’s current example, 
which works only with AppDelegate.  This just can’t be right. 

Nick


 
 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 witness.of.teacht...@gmx.net 
 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
 
 On 07 Feb 2015, at 03:43, Roland King r...@rols.org 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 

Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K

On Feb 13, 2015, at 8:42 AM, David Duncan david.dun...@apple.com wrote:

 Since you elided your header file, this begs a question – is this iOS or OS X?

This is OSX.

I was following Apple’s example, which control-drags from a button to the .m 
file.  The .h file isn’t used. I supplied the shortest possible file to avoid 
confusion.

 
 If I’m not mistaken, subclasses of NSView do not get -initWithCoder:, but 
 rather -initWithFrame:, which begs the question of have you confirmed that 
 your -initWithCoder: method is being called?

Yes. With a breakpoint.

InitWithCoder is called because Runtime Behavior, Instantiation,  Prefer Coder 
is checked in xib’s inspector.
There was quite a discussion about why it works this way 12/23/14 - 12/30/14, 
in response to my request for help, “initWithFrame fails”  Roland King nailed 
it in his email 12/26/2014.


Nick

 
 On Feb 6, 2015, at 6:22 PM, N!K pu56ucl...@alumni.purdue.edu 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 (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
 
 This email sent to david.dun...@apple.com
 
 --
 David Duncan
 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K

On Feb 13, 2015, at 6:49 AM, Uli Kusterer witness.of.teacht...@gmx.net wrote:

 On 12 Feb 2015, at 06:36, N!K pu56ucl...@alumni.purdue.edu 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.
 
 You mean to File's Owner? Is the “Custom Class of File's Owner set to the 
 right class?

Yes.

 Both right-drag and ctrl-drag still work for me to connect button actions in 
 6.1.1 (which is the latest on the MAS).

For me, control-dragging does not work with anything except AppDelegate, 
following Apple’s current example.

 
 I haven’t needed a control for quite some time, and I found that things have 
 changed in Xcode 6.1.1.  I’m attempting to follow Apple’s current 
 instruction.
 
 Here’s the instruction from Apple’s Xcode_Overview.pdf, 2014-03-10, pp 
 64-65. The pictures have to be omitted here due to space constraints of this 
 forum.
 
 Control-drag from the control in Interface Builder to the implementation 
 file. (In the screenshot, the assistant editor displays the implementation 
 file of the view controller for the Warrior button.) Xcode indicates where 
 you can insert an action method in your code.
 
 [picture shows a line with a leading circle in a space in .m]
 
 Release the Control-drag. The assistant editor displays a Connection menu. 
 In this menu, type the name of the action method (chooseWarrior in the 
 screenshot below), and click Connect. 
 
 [picture shows a menu with space to enter name of action]
 
 This is for adding a new outlet/action.

Which also makes the connection.  But following Apple’s current example works 
only with AppDelegate in my system.

 I was under the impression you had an existing one that you just wanted to 
 hook up?

I had also tried entering the IBAction in .h and .m. Initially I failed because 
I was constrained by what I learned in Hillegas’ 3rd edition. I succeeded when 
I followed Roland King’s specific directions, which showed me that some of the 
old constraints no longer apply. Please see my reply to Roland’s email.

Nick

 
 Connect User Interface Objects to Code
 
 In the implementation file, Xcode inserts a skeletal definition for the new 
 method, as shown below. The IBAction return type is a special keyword 
 indicating that this instance method can be connected to your storyboard or 
 xib file. Xcode also sets the action selector for the control to this 
 method. As a result, the method gets invoked whenever the control receives 
 an action message. 
 
 [picture shows - (IBAction)chooseWarrior:(id)sender { }  ]
 
 
 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?
 
 I'm not sure what you're trying to do. Can you give us a better description? 
 Your app delegate has an act: method but you're trying to connect to it by 
 dragging to a MyView?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K
It was left checked. Please see my reply to Dave Duncan.

Nick

On Feb 13, 2015, at 9:16 AM, Kyle Sluder k...@ksluder.com wrote:

 On Fri, Feb 13, 2015, at 10:42 AM, David Duncan wrote:
 Since you elided your header file, this begs a question – is this iOS or
 OS X?
 
 If I’m not mistaken, subclasses of NSView do not get -initWithCoder:, but
 rather -initWithFrame:, which begs the question of have you confirmed
 that your -initWithCoder: method is being called?
 
 This depends on whether the prefer coder checkbox was checked when the
 XIB was authored. If that checkbox is checked, instantiation behaves
 like iOS, where custom views get -initWithCoder: instead of
 -initWithFrame:.
 
 --Kyle Sluder
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/pu56ucla62%40alumni.purdue.edu
 
 This email sent to pu56ucl...@alumni.purdue.edu


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-13 Thread Roland King

 
 Release the Control-drag. The assistant editor displays a Connection menu. 
 In this menu, type the name of the action method (chooseWarrior in the 
 screenshot below), and click Connect. 
 
 [picture shows a menu with space to enter name of action]
 
 This is for adding a new outlet/action. I was under the impression you had an 
 existing one that you just wanted to hook up?

I didn't read it that way. Further on down he says Insertion of  - 
(IBAction)act:(id)sender { } occurs only in my AppDelegate which I took to 
mean the drag-to-insert-method-stub bit doesn't work. I suggested just adding 
the IBAction by hand in the .h file. I'm not sure I ever tried the auto-add 
method stuff so I have no idea if it works, but I do know typing the IBAction 
code in by hand does and takes about 2 seconds. 

 
 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?
 
 I'm not sure what you're trying to do. Can you give us a better description? 
 Your app delegate has an act: method but you're trying to connect to it by 
 dragging to a MyView?

The way I read it is he wants an act: method on his MyView and is trying to add 
the method by dragging to the interface/implementation file and is failing to 
get the code inserted into the file, but when he drags to the Delegate object 
then it works, and it also connects it. I also asked if the view he's dragging 
to has its class set correctly to MyView because if it's not, that would 
probably indicate both why the method isn't added by drag and why it can't be 
connected. 


 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com 
 mailto:Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com 
 http://lists.apple.com/
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org 
 https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
 
 This email sent to r...@rols.org mailto:r...@rols.org
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-13 Thread Uli Kusterer
On 12 Feb 2015, at 06:36, N!K pu56ucl...@alumni.purdue.edu 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.

 You mean to File's Owner? Is the Custom Class of File's Owner set to the 
right class? Both right-drag and ctrl-drag still work for me to connect button 
actions in 6.1.1 (which is the latest on the MAS).

 I haven’t needed a control for quite some time, and I found that things have 
 changed in Xcode 6.1.1.  I’m attempting to follow Apple’s current instruction.
 
 Here’s the instruction from Apple’s Xcode_Overview.pdf, 2014-03-10, pp 64-65. 
 The pictures have to be omitted here due to space constraints of this forum.
 
 Control-drag from the control in Interface Builder to the implementation 
 file. (In the screenshot, the assistant editor displays the implementation 
 file of the view controller for the Warrior button.) Xcode indicates where 
 you can insert an action method in your code.
 
 [picture shows a line with a leading circle in a space in .m]
 
 Release the Control-drag. The assistant editor displays a Connection menu. In 
 this menu, type the name of the action method (chooseWarrior in the 
 screenshot below), and click Connect. 
 
 [picture shows a menu with space to enter name of action]

 This is for adding a new outlet/action. I was under the impression you had an 
existing one that you just wanted to hook up?

 Connect User Interface Objects to Code
 
 In the implementation file, Xcode inserts a skeletal definition for the new 
 method, as shown below. The IBAction return type is a special keyword 
 indicating that this instance method can be connected to your storyboard or 
 xib file. Xcode also sets the action selector for the control to this method. 
 As a result, the method gets invoked whenever the control receives an action 
 message. 
 
 [picture shows - (IBAction)chooseWarrior:(id)sender { }  ]
 
 
 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?

I'm not sure what you're trying to do. Can you give us a better description? 
Your app delegate has an act: method but you're trying to connect to it by 
dragging to a MyView?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-13 Thread David Duncan
Since you elided your header file, this begs a question – is this iOS or OS X?

If I’m not mistaken, subclasses of NSView do not get -initWithCoder:, but 
rather -initWithFrame:, which begs the question of have you confirmed that your 
-initWithCoder: method is being called?

 On Feb 6, 2015, at 6:22 PM, N!K pu56ucl...@alumni.purdue.edu 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 (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
 
 This email sent to david.dun...@apple.com

--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-13 Thread Kyle Sluder
On Fri, Feb 13, 2015, at 10:42 AM, David Duncan wrote:
 Since you elided your header file, this begs a question – is this iOS or
 OS X?
 
 If I’m not mistaken, subclasses of NSView do not get -initWithCoder:, but
 rather -initWithFrame:, which begs the question of have you confirmed
 that your -initWithCoder: method is being called?

This depends on whether the prefer coder checkbox was checked when the
XIB was authored. If that checkbox is checked, instantiation behaves
like iOS, where custom views get -initWithCoder: instead of
-initWithFrame:.

--Kyle Sluder

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-13 Thread Roland King

 On 14 Feb 2015, at 01:16, Kyle Sluder k...@ksluder.com wrote:
 
 On Fri, Feb 13, 2015, at 10:42 AM, David Duncan wrote:
 Since you elided your header file, this begs a question – is this iOS or
 OS X?
 
 If I’m not mistaken, subclasses of NSView do not get -initWithCoder:, but
 rather -initWithFrame:, which begs the question of have you confirmed
 that your -initWithCoder: method is being called?
 
 This depends on whether the prefer coder checkbox was checked when the
 XIB was authored. If that checkbox is checked, instantiation behaves
 like iOS, where custom views get -initWithCoder: instead of
 -initWithFrame:.
 

From the fact in the original message that the two variables remained at the 
default of zero my assumption was that neither piece of advice from the 
previous thread on this was followed, those being :-

1) Leave the 'prefer coder' checkbox checked, because it's more consistent, 
arguably fixes a longstanding bug, and remembering when you've turned it on and 
off is likely to lead to confusion. 
2) Don't put initialisation code directly in initWithCoder: but factor it out 
to a separate method called from all the init routines, so it doesn't matter 
which one is called, they all funnel through the same setup code. 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-11 Thread N!K
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.


I haven’t needed a control for quite some time, and I found that things have 
changed in Xcode 6.1.1.  I’m attempting to follow Apple’s current instruction.

Here’s the instruction from Apple’s Xcode_Overview.pdf, 2014-03-10, pp 64-65. 
The pictures have to be omitted here due to space constraints of this forum.

Control-drag from the control in Interface Builder to the implementation file. 
(In the screenshot, the assistant editor displays the implementation file of 
the view controller for the Warrior button.) Xcode indicates where you can 
insert an action method in your code.

[picture shows a line with a leading circle in a space in .m]

Release the Control-drag. The assistant editor displays a Connection menu. In 
this menu, type the name of the action method (chooseWarrior in the screenshot 
below), and click Connect. 

[picture shows a menu with space to enter name of action]

Connect User Interface Objects to Code

In the implementation file, Xcode inserts a skeletal definition for the new 
method, as shown below. The IBAction return type is a special keyword 
indicating that this instance method can be connected to your storyboard or xib 
file. Xcode also sets the action selector for the control to this method. As a 
result, the method gets invoked whenever the control receives an action 
message. 

[picture shows - (IBAction)chooseWarrior:(id)sender { }  ]


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?

Nick



On Feb 7, 2015, at 10:27 PM, Uli Kusterer witness.of.teacht...@gmx.net 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
 
 On 07 Feb 2015, at 03:43, Roland King r...@rols.org 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 pu56ucl...@alumni.purdue.edu 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) {
  

Re: Connecting a button to MyView zeros integers

2015-02-11 Thread Roland King

 On 12 Feb 2015, at 13:36, N!K pu56ucl...@alumni.purdue.edu 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 witness.of.teacht...@gmx.net 
 mailto:witness.of.teacht...@gmx.net 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 r...@rols.org 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 pu56ucl...@alumni.purdue.edu 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 

Re: Connecting a button to MyView zeros integers

2015-02-07 Thread Uli Kusterer
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

 On 07 Feb 2015, at 03:43, Roland King r...@rols.org 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 pu56ucl...@alumni.purdue.edu 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 (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
 
 This email sent to r...@rols.org
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/witness.of.teachtext%40gmx.net
 
 This email sent to witness.of.teacht...@gmx.net


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-06 Thread Roland King
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 pu56ucl...@alumni.purdue.edu 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 (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
 
 This email sent to r...@rols.org

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com