New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

Start a Discussion

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Custom View problems...

Post Reply New Thread Subscribe

Thread Tools

Member Since: Sep 14, 2008
Posts: 18
Meds is on a distinguished road

Meds is offline
All right. I'm trying to work with custom views a little and this is confusing me.

I created the custom view and wrote the files, and this is my app controller calling a method on an object of my custom class:

- (IBAction)fillBoxes:(id)sender {
	float topCircleValue = [topCircle floatValue];
	float bottomCircleValue = [bottomCircle floatValue];
	NSLog(@"We're in! %f", topCircleValue);
	[leftFillBox drawFillWithSliderValue:topCircleValue];
	[rightFillBox drawFillWithSliderValue:bottomCircleValue];
left and rightFillBox are my objects of class CustomView. Here's my CustomView.h file:

#import <Cocoa/Cocoa.h>

@interface CustomView : NSView {


- (void)drawFillWithSliderValue:(CGFloat)sliderValue;

And .m file:

#import "CustomView.h"

@implementation CustomView

- (void)drawFillWithSliderValue:(CGFloat)sliderValue {
	int sliderValueWholeNumber = (int)sliderValue;
	NSLog(@"%d", sliderValueWholeNumber);
	NSColor* red = [NSColor redColor];
	[red set];
	NSRect selfTest = [self bounds];

        NSLog(@"%@", NSStringFromRect(selfTest));
All of the NSLog's are behaving exactly as they should. My objective is to get it to draw a rect using the bounds with the height coordinate replaced with sliderValueWholeNumber, but I can't even get this simple test to work. Every time, nothing. It's not filling the custom view area with red. What am I doing wrong?
QUOTE Thanks

Member Since: Jan 25, 2009
Posts: 2
jpimbert is on a distinguished road

jpimbert is offline
In your method drawFillWithSliderValue: sliderValue, you must call
[self setNeedsDisplay:YES]
The actual drawing takes place in the method -(void)drawRect: (NSRect)rect which is called automatically by Cocoa when the View is displayed on the screen.
I recommend you to
  1. rename your method setSliderValue; you will be fully Cocoa compliant
  2. keep only the setting of sliderValueWholeNumber in this method and the call to setNeedsDisplay
  3. put the drawing instructions of your method into a drawRect method (superseding the empty NSView method)
QUOTE Thanks

Post Reply New Thread Subscribe

« XCode & braces | Terminal Tabs »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Starter
Last Post
IMAC 25 - OSX 10.5.5 Corrupt files, Losing work & view problems MargaretM OS X - Operating System 5 07-10-2009 04:24 PM
Realtek sound problems, lag problems Starflame Running Windows (or anything else) on your Mac 2 11-08-2008 10:54 AM
iMac + MacBook MacBookPro Internet Connection Problems stevend Internet, Networking, and Wireless 2 10-05-2008 11:19 AM
Problems with leopard an gael cliste OS X - Operating System 2 09-18-2008 09:37 AM
Panther view settings not sticking! Bmode OS X - Operating System 0 01-26-2004 04:17 AM

All times are GMT -4. The time now is 02:20 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.

Welcome to

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!

(4 digit year)

Already a member?