Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
so to use it you have to either give NSButton a custom cell (which I don't know how to do)
.
Give%20a%20ButtonCell%20a%20Class.png


is this what you mean?
 
i knew how to do it but he didnt. i was see if that what he dint know how to do.

Yeah, sorry. I was misinterpreting the problem; you already know how to use the CCDColoredButtonCell class, and I didn't. But If you already know how to use the class, then implementing code like mine should be pretty easy.
 
Can you post you exact code?

Seconded. My code works fine for me.

And to loop, you can just say that once the variable for counting is five (or the number of how many colors you're looping through) subtract five from it so you're back at zero or whatever and can start over.
 
What the Button Does


The video was done a Imac with 3GB RAM more than my 1Gb RAM Hackingtosh
so that is what i believe i have to use more object between different colors. if soo than this project is going not going be universal. :(

but here is the updated project file.

and i made a video of what the code does and how my connection were set up. in IB.
 

Attachments

  • colorButtonTest.zip
    195 KB · Views: 91
I had a suspicion it was as simple as a little typo. You need to review some of the fundamentals of C.

As far as the looping goes, you need to find a way to detect when arrayIndex runs past the limit of the array and revert it to zero. The proper form to use would be:

Code:
arrayIndex++ ;
if ( arrayIndex >= [colorArray count] ) arrayIndex = 0 ;
( using [colorArray count] instead of a constant like 3 means you can just change the array size and the code will still work )

But that is a minor thing. I changed just one character in the .h file and it worked correctly.

Consider these two lines
.h file:
Code:
NSUInteger   *arrayIndex;
and .m file:
Code:
[self setButtonColor:[colorArray objectAtIndex:arrayIndex]];

Now go to the basic C books and Cocoa documentation and see if you can figure out what the problem is with that (hint: study up on what pointers are and how to use them).

(edit)
Cocoa can be confusing: not everything that starts with "NS…" is an object (if it is an object, you cannot use basic C math on it). The easiest way to tell the difference is to look at the documentation. All the objects that begin with "NS…" are listed as classes under the AppKit or Foundation Framework Reference pages, all the things which are not objects are listed in the "Data Types" sections of AppKit or Foundation. This is an important fundamental to learn when working with Cocoa and C.
 
As far as the looping goes, you need to find a way to detect when arrayIndex runs past the limit of the array and revert it to zero. The proper form to use would be:

Code:
arrayIndex++ ;
if ( arrayIndex >= [colorArray count] ) arrayIndex = 0 ;

Just because I love mod:
Code:
arrayIndex++;
arrayIndex %= [colorArray count];

-Lee

EDIT:
or
Code:
arrayIndex = (arrayIndex+1) % [colorArray count];

I'm not saying these are better or clearer than Sydde's examples, I just love mod.
 
Just because I love mod:
Code:
arrayIndex++;
arrayIndex %= [colorArray count];

-Lee

EDIT:
or
Code:
arrayIndex = (arrayIndex+1) % [colorArray count];

I'm not saying these are better or clearer than Sydde's examples, I just love mod.

I used "if" in keeping with the thread title. To really confuse the issue, one could also write

Code:
arrayIndex = ( ( ( arrayIndex + 1 ) >= [colorArray count] ) ? 0 : arrayIndex + 1 ) ;

I have a horrible habit of overusing that format, but at least I also overuse subscripts and always space everything out.
 
To really confuse the issue, one could also write

Code:
arrayIndex = ( ( ( arrayIndex + 1 ) >= [colorArray count] ) ? 0 : arrayIndex + 1 ) ;

how is that confuseing the issue. Lee uses a Module and you used a trinary operator.
thanks any way.
-----------------------------------------------------------------------------
@sydde:

so in other ways NSUInteger is not a object there fore it can not be assigned a pointer to it. so take off the "*" and i should be all set.
good to know now. i thoght every thing with NS.. was a Object.
i go try it out.
 
so in other ways NSUInteger is not a object there fore it can not be assigned a pointer to it. so take off the "*" and i should be all set.

Half-right. You can assign a pointer to anything, you just have to know when that is a good idea and how to use the pointer. This can be a difficult concept to get the hang of.

Can you explain the odd incrementing behavior of arrayIndex you experienced? If so, it will help you a little towards understanding the ways pointers can be useful.
 
i give it a go.

arrayIndex became a pointer to NSUInteger. when arrayIndex = 0; it assigned the NSUInteger the value 0 but it did not assign arrayIndex the value 0;

the reason the *arrayIndex didn't work with the code that was on the Low End computer, because the size of the pointer variable vary. unlike a variable the size of the NSUInteger was specified.

the variable sets aside a memory location for the value that it is about to store.

the pointer variable sets aside a address for the data the is going be stored in the pointer.

but this is why i think it give different outputs

here is the quick reading im doing about pointers.
sydde you are right studying about pointers.
Pointer tutorial
<This material is hereby placed in the public domain>


i thank you all for helping me succeed in the part of my project. ive learned a lot. When my application is finished will add you in my credits as part of development of the Application. I tank you All

Enigmod, sydde, and JoshDC thank you all for your help.
 
HERE is the Finished Product of the Colored Button.
this is not the application but part of what is going to be in the finished application

i have add some thing to the code :) check it out and let me know what you think. :p
 

Attachments

  • colorButton.zip
    207.6 KB · Views: 73
Now add three more buttons and make them all change when you click one. Hint: in most cases, a button's target points to some object other than the button itself.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.