• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Custom view - newbie stumped
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Custom view - newbie stumped


  • Subject: Custom view - newbie stumped
  • From: Kenny Millar <email@hidden>
  • Date: Mon, 24 Apr 2006 16:45:17 +0100

Hi,

As a prototype for a part of a bigger project I hop to do, I created a very simple Cocoa app to test some ideas.
However I'm stopped at the first hurdle....


I took the following steps...

Created a new Cocoa application.
Opened the NIB file in IB and created a sub-class of NSView called 'TLView'
I added an Action to TLView, called 'addTrack'
I created the files for 'TLView' and included them in my project.
I placed a button on the window and connected it to the 'addTrack' action.
I placed a Custom View on the window and set it's custom class to be 'TLView'


In the drawRect for TLView I simply draw the bounds rectangle.

This all works fine - up to a point.
In the action for 'addTrack' I do :
	[self setNeedsDisplay:YES];

But here's the problem, although that line of code gets called, the view doesn't re-draw!?!
If I re-size the window, then as I'd expect, drawRect gets called again and again, but never from my 'addTrack' method.
(I have NSLog(...) statements so I can see what's getting called when).


The entire implementation of TLView is below (it's small).

When I run the app, the run log shows...
[Session started at 2006-04-24 16:43:10 +0100.]
2006-04-24 16:43:10.277 LiveShowTimeLine[5806] Drawing...
2006-04-24 16:43:11.912 LiveShowTimeLine[5806] Add track
2006-04-24 16:43:12.264 LiveShowTimeLine[5806] Add track
2006-04-24 16:43:12.463 LiveShowTimeLine[5806] Add track
2006-04-24 16:43:12.640 LiveShowTimeLine[5806] Add track
2006-04-24 16:43:12.840 LiveShowTimeLine[5806] Add track

But I'd expect it to do something more like.... (hand edited)....
[Session started at 2006-04-24 16:43:10 +0100.]
2006-04-24 16:43:10.277 LiveShowTimeLine[5806] Drawing...
2006-04-24 16:43:11.912 LiveShowTimeLine[5806] Add track
2006-04-24 16:43:12.277 LiveShowTimeLine[5806] Drawing...
2006-04-24 16:43:13.912 LiveShowTimeLine[5806] Add track
2006-04-24 16:43:14.277 LiveShowTimeLine[5806] Drawing...
2006-04-24 16:43:15.912 LiveShowTimeLine[5806] Add track



What do I need to do to get the view to redraw its self, as a result of things I do in 'addTrack' ?

Thanks in advance
Kenny.

#import "TLView.h"

@implementation TLView

- (id)initWithFrame:(NSRect)frameRect
{
	if ((self = [super initWithFrame:frameRect]) != nil) {
		// Add initialization code here
	}
	return self;
}

- (void)drawRect:(NSRect)rect
{
	NSRect	bounds;
	bounds = [self bounds];

	[NSBezierPath strokeRect:bounds];

	NSLog(@"Drawing...");
}

- (IBAction) addTrack:(id)sender;
{
	NSLog(@"Add track");
	[self setNeedsDisplay:YES];
}
@end

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Custom view - newbie stumped
      • From: "M. Uli Kusterer" <email@hidden>
    • Re: Custom view - newbie stumped
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: Superimpose a NSTextField over NSImageView? [SOLVED]
  • Next by Date: 3rd unwanted contex
  • Previous by thread: Re: Getting a table to resize columns. I'm doing everything right but it's not working?
  • Next by thread: Re: Custom view - newbie stumped
  • Index(es):
    • Date
    • Thread