PDA

View Full Version : Naming Objects in Interface Builder?




Fritzables
Jun 2, 2011, 09:37 PM
Hi All,

I am into my second week of the Mac environment after buying one of the new iMacs.

Over the years I have developed using MS's Visual Studio (C#) and have now jumped deep into XCode.

The transition to the new way of programming has been frustrating but I am sure the penny will eventually drop.

The part I am having trouble understanding is that under VS, it was a simple method of giving a user friendly name to a control. For example, if i was to have a TableView control, I could rename it to MyTable by editing the Name parameter in Properties of that control - at that point I can make reference to it in my code.

In XCode, I am developing an app that has a couple of NSTableViews within the same window. Where in the Interface Builder can I assign a name that will allow me to gain access through my code.

Is it the Identity field??

Pete



rossipoo
Jun 2, 2011, 10:29 PM
I'm not sure how c# works with the interface connections. The identity field cannot be used to refer to a control object by name in code, it is for identifying a control when receiving a message from potentially multiple senders.

In ObjC and Xcode, you must have an IBOutlet property in whatever class is related to that control, which must be connected to the control, by right-clicking on the object with that property and dragging from the property to the control.

Assuming you are using XC4, you can right-click drag from the control to the code if you bring up both together and it will create a new property connected to that control.

jiminaus
Jun 2, 2011, 10:30 PM
Objective-C / Cocoa does things differently to what you're used to. You will need to go back to basics and learn again. Your previous experience will be both a help (some concepts are the same) and hindrance (you'll have to unlearn some things and that can be hard).

Objects in interface builder are connected to outlets in other objects. These outlets are instance variable or properties. It's name of these outlets that you use in your code.

Follow through the Cocoa Application Tutorial (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCTutorial).

Fritzables
Jun 2, 2011, 10:55 PM
Thanks guys for the help on this.
I have just grabbed the Cocoa Turorial, so I'll spend the weekend getting my head around it all.


Pete

PatrickCocoa
Jun 2, 2011, 11:15 PM
There are a lot of differences between developing for Windows using Visual Studio and developing for Mac or iOS using Xcode. There will be many bumps in the road, not because Mac/Xcode is worse than Windows/Visual Studio, but because it's different.

Sources of Difference:
1. Operating Systems. Windows vs. Mac OS. They're different, so your overall computing experience is different, particularly the Finder vs. Windows Explorer.

2. Development Environment. Visual Studio vs. Xcode. As you've seen, there are differences both in the way information is presented and in certain fundamental concepts in how interface elements are related to code.

3. APIs. MFC vs. Cocoa. There are many differences here, obviously.

4. Programming Languages. C++ vs. Objective C. Many differences here, for example in syntax. Also Apple likes the model view controller setup for most things.

5. Interface. Windows vs. Mac OS vs. iOS. Apple wants you to strive for simplicity, beauty, and discoverablity, Microsoft wants you to strive for functionality and features. Either way can be argued to be superior, but if you're developing for the Mac, your users will expect you to present your program in a certain way.

Fritzables
Jun 3, 2011, 02:41 AM
G'Day PatrickCocoa,

Totally agree - it will just take time and I have no problems with that. I have been coding under Windows since the 3.1 days - yea, a long time ago.

That's the first thing I noticed was the difference in Syntax but I quickly caught up and could understand what the code was doing.

The problem is that I am a very impatient person, I have an app that isn't available under Mac and I want to write it NOW for all to have and use.

I seriously need to slow down......


Pete

jiminaus
Jun 3, 2011, 03:54 AM
That's the first thing I noticed was the difference in Syntax but I quickly caught up and could understand what the code was doing.

The problem is that I am a very impatient person, I have an app that isn't available under Mac and I want to write it NOW for all to have and use.

I seriously need to slow down......


A couple of words of advice, if I may.

If you've not already, jump start into XCode 4. XCode 4 is stable. There's no point for someone of your experience learning XCode 3, then having to learn XCode 4. You'll probably find XCode 4 more palatable to XCode 3 as well.

Get the 4th edition of Hillegass's Cocoa® Programming for Mac® OS X. It's out at the of this month. (Is that right? I couldn't find Hillegass's post on this forum?).

In the meantime, stop being programmer, and spend time on Mac OS X being as a user. Really get to know Mac OS X. Study how good Mac Apps behave and interact with you. Do this together with absorbing the Apple Human Interface Guidelines (http://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines).

Fritzables
Jun 3, 2011, 04:33 AM
Thanks jiminaus,

Yea, only using XCode 3.x

Spend the $5 ya reckon.... done, I'll do it now.
Thanks for the tip.

Pete