Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zijianz

macrumors newbie
Original poster
May 21, 2012
7
0
Hi,

I am currently studying the class of programming in iPhone from stanford. I saw the instructor was trying to program a calculator.

First, he created a label to display the digits. He dragged it from the UI view to the code to establish the connection.

He dragged he label to 'ViewController.h' creating a new '@property'.

But, when he was trying to create the digit button. He just dragged the button directly to 'ViewController.m' but not .h. Creating only a method like below,
Code:
- (IBAction) digitPressed : (UIButton *) sender
 {
       NSString *digit = [sender currentTittle];
}

Here are my questions,

1. If the label is just a property, what is the class? The entire view?
2. Does '@property' have the same meaning of "member" in c++?
3. Why does the button not being a property but just a simple method in the implementation file.
4. And in c++, we need to announce the method first in the header file, then we specify the action of that method in the implementation file. But it seems in this program he didn't announce that "digitPressed", but simply in the .m file. why.
5. It said when the digit being pressed, it will send a string pointer. Could anyone tell me who it is sending to?

THank you so much for you help and please forgive that I am a starter in this field.
 
Last edited by a moderator:
Basically, the label is just a property, properties generates getters/setters, there is a differen if you declared them in an private interface or an public interface, this only means if you want to expose the property to other classes.
I have no idea what member is in C++, but I explained what it is above (you can read this in any Obj C book too).

"Why does the button not being a property but just a simple method in the implementation file." this sentence makes no sense at all.
You can assign a button an Outlet, this means your code knows where the button is in the XIB after it's been initialised, you can hook up methods (IBActions for XIB buttons), to the actual xib file, and that's what he's probably doing..

Basically, that is what you need to do, if you have this ->
Code:
 - (IBAction) digitPressed : (UIButton *) sender {}
as your method implementation, you need this in your header file (this is not needed, it's just to expose them & or overview for yourself, you can also do this in a private interface to not expose it.
Code:
- (IBAction) digitPressed : (UIButton *) sender;

The digitbutton pressed itself will not create a string pointer.
But since you assigned that method to the button in the XIB, it will know who the sender is, the sender has a title, therefore you can get the STRING POINTER like you call it, from the Title of the sender. Which he is doing here ->
Code:
 NSString *digit = [sender currentTitle];

You are off with Objective-C itself, i'd recommand reading a book first, look what the difference is with property's ivars, interfaces, delegations, IBActions/Voids, how the parameters get build up, etc.
 
Hmm, I thought the Stanford classes were recommended (by you and others) as a good way of learning Objective-C. Is that not the case?

It's a good way of studying the UI for iPhone and the most general concepts, but it expects you to have some Objective-C knowledge, (which most people do start off with), and well, the difference, in my opinion for this task, is you should know the difference between a void/IBAction, or at least explain what it does. etc.
I mostly forward people to the Stanford courses because you can get a grip fast on what Objective-C can do, but apparently in his case, he isn't up to date just quite yet, so then I recommand reading some iphone books first :)
Hope that made any sense
 
It's a good way of studying the UI for iPhone and the most general concepts, but it expects you to have some Objective-C knowledge...

Hmm, according to the course description:
Prerequisites: C language and programming experience at the level of 106B (Programming Abstractions) or X.
And the first lecture is titled "MVC and Introduction to Objective-C". Doesn't seem to expect Objective-C knowledge to me.
 
Hai Dejo,

I've did the course myself, I was more expressing my own feeling about the course. I've had some background, and you get thrown in real hard in the course.
You get the basics like, what is this and that, but after like 1 session, you get thrown in hard, so to really study the basics thorough, you should avoid the lessons and study something else. (just personal experience)
 
What the course prerequisites says, and what one needs to know to do well in a class are two different things. That's the reason why a lot of students end up starting a course needed for graduation more than once (maybe not a Stanford, but at places where the typical students are less elite and well prepared).

If you really want to understand this topic, courses or textbooks on programming language design and on compiler implementation might also be helpful.
 
To be clear, I am not in a great position to judge the ability of the Stanford classes to educate a beginner in Objective-C, since I had already a pretty good handle on the language before encountering them.
 
To be clear, I am not in a great position to judge the ability of the Stanford classes to educate a beginner in Objective-C, since I had already a pretty good handle on the language before encountering them.

The easiest language to learn is one you already know.

I learn new things everyday about stuff of which I'm supposedly an expert user.
 
My personal learning process went something like this:
- my dad tried teaching me programming on and off since fifth grade.
- In seventh grade, I started trying to learn, straight from The C Programming Language, but didn't get halfway through the first section before giving up. However, what I did learn made me enjoy/appreciate algebra vastly more.
- When the iOS SDK was released, I dived right into it. I referred to a book on Cocoa a little bit to figure out the basics of Obj-C and IBActions. I managed to make a game like Taboo (it had a large array of arrays of related NSStrings. It would pick a random array, and then display the strings in a random order. There was a timer with a progress bars, and buttons for awarding points to players. There were too many bugs I didn't know how to fix, so I never tried selling it.)
- A year passed. I forced myself to read The C Programming Language again... Gave up when I reached pointers. I discovered the Stanford iOS lectures, and by following those was able to make a few apps. I signed up for the paid iOS developer program, tested apps on my iPhone and showed them off for a year, and then my membership expired without my submitting anything ever.
- I kept on making apps and testing them in the simulator for anothe year. Eventually I made Egg Drop!, decided it was my first app I was ready to sell, signed up for iOS developer program again, and sold it. This membership expires in about a week, now, and Egg Drop! has only brought in ~$80, while Quick Clips (my second app, ad supported with a $0.99 in app premium upgrade,) has brought in ~$12. So I haven't quite broke even and won't be renewing right now.
- I signed up in January as a Mac App Store Developer. I've been more formally teaching myself C with Learn C The Hard Way, and I'm being taught C++ in school.

TL;DR: 80-90% of what I needed to learn to publish my first app on the iOS app store came from Stanford's iOS classes. The rest came from the opening 2 sections of The C Programming Language and tinkering around with Apple's developer tools while I was in middle/jr. high school.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.