Cocoa is sucking and ruling synchronously

Slowly I’m getting a feeling of how to create apps with the help of objective-c and cocoa. And it both sucks and rules at the same time!

At first, the things I like. Bindings. They are impressing! Generating small apps without a single line of code, visualizing data with several UI components fast. Makes really fun. Also objective-c as a programming language is cool combined with cocoa as the framework, even if objective-c feels a little bit outdated compared to something like C#.

Now what really sucks. Creating layouts with the interface builder. In took me nearly an hour, to complete a simple view like this:

A basic window with a NSSPlitView and a NSOutlineView. At first, positioning the elements not to overlap was a pain in the ass. Second, my simple wish to fix the size of the left view seemed to be impossible within the interface builder. After a little bit of googling I’ve found following snippet.

-(void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:
(NSSize)oldSize
{
	CGFloat dividerThickness = [sender dividerThickness];
	NSRect leftRect  = [[[sender subviews] objectAtIndex:0] frame];
	NSRect rightRect = [[[sender subviews] objectAtIndex:1] frame];
	NSRect newFrame  = [sender frame];
 
	leftRect.size.height = newFrame.size.height;
	leftRect.origin = NSMakePoint(0, 0);
	rightRect.size.width = newFrame.size.width - leftRect.size.width
	- dividerThickness;
	rightRect.size.height = newFrame.size.height;
	rightRect.origin.x = leftRect.size.width + dividerThickness;
 
	[[[sender subviews] objectAtIndex:0] setFrame:leftRect];
	[[[sender subviews] objectAtIndex:1] setFrame:rightRect];
}

As nearly every component can have a delegate defined which is triggered at certain actions, this one is triggered on resizing the split view. Simply, the old size of the left side is taken and kept, while the new size of the right side will be passed through.

Now going to fill this stuff with life!

Category: Macintosh, Programmieren Comment »


Leave a Reply



 

Back to top