PDA

View Full Version : My Code Is Wacked




mack255
Apr 3, 2009, 09:46 AM
Whats wrong with my code i said to change the button title to orange when it says what color is the sun but instead it changes when it says wrong please help



caveman_uk
Apr 3, 2009, 09:53 AM
= doesn't compare things. It assigns values. Use == to compare. But you can't in this case as you'd be comparing an object's address against a literal string. You need to use the isEqualToString: method.

mack255
Apr 3, 2009, 09:55 AM
how do i use that method

mack255
Apr 3, 2009, 09:58 AM
a better question is how would i write the code

dejo
Apr 3, 2009, 10:12 AM
a better question is how would i write the code
The same way you call any Objective-C method. With a [receiver message]
where "receiver" is the class or instance and "message" is the method, with arguments, if necessary.

lazydog
Apr 3, 2009, 10:16 AM
Actually, the Sun is white!

b e n

mack255
Apr 3, 2009, 10:25 AM
im new can you please tell me the full code im brand new started a couple days ago

dejo
Apr 3, 2009, 10:28 AM
im new can you please tell me the full code im brand new started a couple days ago
This is pretty basic Objective-C programming concepts. I'd suggest you step back and learn the basics before you continue with any real coding.

mack255
Apr 3, 2009, 10:33 AM
please just tell me i don't understand i couldn't find any good websites to teach me and im broke and can't buy any books

eddietr
Apr 3, 2009, 10:37 AM
im new can you please tell me the full code im brand new started a couple days ago

Well, if you're learning you probably want to understand the concepts rather than assign someone to write code for you. The Apple developer docs are more than sufficient if you don't want to buy a book right now.

So do you understand the concept that objects belong to a class and can respond to messages (also called instance methods)? If so, then the strings you have belong to the class NSString, and so you can find various instance methods in the docs for NSString. There is a method there that allows you to compare one instance of NSString to another.

Your overall approach to managing questions and answers like this will get pretty painful quickly. But it's a good learning exercise, and then you can learn ways to make this easier and more efficient.

But I would point out that string comparison is not your main problem. The issue is the logic itself. The method that is fired by the top button won't be executed until after the user hits that button.

So that's really the reason why you don't get the button "Orange" until after the user has pressed that top button.

Does that make sense?

dejo
Apr 3, 2009, 10:41 AM
please just tell me i don't understand i couldn't find any good websites to teach me and im broke and can't buy any books
Have you checked out the guides and stickies at the top of the iPhone Programming forum?

johnnybluejeans
Apr 3, 2009, 10:45 AM
please just tell me i don't understand i couldn't find any good websites to teach me and im broke and can't buy any books

If someone "just tells you" you won't learn anything. You couldn't find any good websites??? Did you even look? Here, I have a link that will help you:

http://***********/?q=objective+c+tutorial+iphone

mack255
Apr 3, 2009, 10:54 AM
actually i learn really well if someone tells me the code

dejo
Apr 3, 2009, 11:09 AM
actually i learn really well if someone tells me the code
Of course! No learning required then. You've already got the answer! :D

eddietr
Apr 3, 2009, 11:59 AM
actually i learn really well if someone tells me the code

Read my post again, I told you exactly which class to look in.

I think the point you may be missing is that coding with Cocoa or any similar framework is a process of looking through the framework documentation for something you need, and then using it in your code. This is true even after you've done this for decades.

So if you don't have the time or focus or energy or whatever to crack open the documentation, then you've just picked a bad hobby for yourself. Not trying to be mean, it's just how programming works. If you don't want to do it, then save yourself a lot of trouble and just don't do it. It's that easy.

But if you do decide to put the effort in, then we can talk about the logic problems (which I wrote about already in my earlier post.)

Good luck whatever you decide to do. I would recommend the hello world primer on the Apple developer site. Or any of the other video and web primers that people talk about on this forum. Just to get the basics down first.

BTW, your code already has multiple examples of sending messages to objects. This is exactly what you need to do with your NSStrings. So if you wrote your code, then you know what to do. If you just copied that code from someone else, then I think you've proven that you don't really learn from copying code.

johnnybluejeans
Apr 3, 2009, 12:38 PM
I'm an awesome physicist when someone writes all the proofs for me.