Thanks for the quick reply. The following code fragments show what's going on

It's weird how it correctly "bounces" when you try to go "up" too far, but will just keep going when you try to go "down". I'm sure there might be a use for this behavior, but not for me!
The delegate header ...
//
// JointPicker.h
// Picker1
//
// Created by Quilpole on 5/31/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface JointPicker : UIPickerView <UIPickerViewDelegate> {
NSArray *pickerViewArrayWidths;
NSArray *pickerViewArrayDepths;
NSInteger widthValue;
NSInteger depthValue;
}
@property(nonatomic) IBOutlet NSInteger widthValue;
@property(nonatomic) IBOutlet NSInteger depthValue;
@end
The delegate body ...
//
// JointPicker.m
// Picker1
//
// Created by Quilpole on 5/31/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "JointPicker.h"
@implementation JointPicker
@synthesize widthValue;
@synthesize depthValue;
- (id) init {
self = [super init];
if (self) {
pickerViewArrayWidths = [[NSArray arrayWithObjects

"1/8\"",@"1/4\"",@"3/8\"",@"1/2\"",@"5/8\"",@"3/4\"",@"7/8\"",@"1\"",nil] retain];
pickerViewArrayDepths = [[NSArray arrayWithObjects

"1/8\"",@"1/4\"",@"3/8\"",@"1/2\"",nil] retain];
}
return self;
}
- (void)dealloc {
[pickerViewArrayWidths release];
[pickerViewArrayDepths release];
[super dealloc];
}
// Implement PickerView delegate methods.
- (void) pickerView

UIPickerView *) pickerView didSelectRow

NSInteger) row inComponent

NSInteger) component {
// Note the selection.
if (component == 0) {
widthValue = row + 1;
} else {
depthValue = row + 1;
}
}
- (NSString *) pickerView

UIPickerView *) pickerView titleForRow

NSInteger)row forComponent

NSInteger)component {
NSString *returnStr;
if (component == 0) {
if (row < [pickerViewArrayWidths count]) {
returnStr = [pickerViewArrayWidths objectAtIndex:row];
} else {
// If the method is somehow called with a "row" that is out of range, then
// simply return a nil.
returnStr = nil;
};
} else {
if (row < [pickerViewArrayDepths count]) {
returnStr = [pickerViewArrayDepths objectAtIndex:row];
} else {
// If the method is somehow called with a "row" that is out of range, then
// simply return a nil.
returnStr = nil;
}
}
return returnStr;
}
- (CGFloat) pickerView

UIPickerView *) pickerView widthForComponent

NSInteger) component {
CGFloat componentWidth;
if (component == 0) {
componentWidth = 50.0; // First column size for Width Names
} else {
componentWidth = 50.0; // Second column size for Depth Names
}
return componentWidth;
}
- (CGFloat) pickerView

UIPickerView *) pickerView rowHeightForComponent

NSInteger) component {
return 30.0;
}
- (CGFloat) pickerView

UIPickerView *) pickerView numberOfRowsInComponent

NSInteger) component {
CGFloat rowCount;
if (component == 0) {
rowCount = [pickerViewArrayWidths count];
} else {
rowCount = [pickerViewArrayDepths count];
}
return rowCount;
}
- (NSInteger)numberOfComponentsInPickerView

UIPickerView *) pickerView {
return 2;
}
@end
Declared in the view controller using ...
JointPicker *myJointPicker;
Initialized in the view controller using ...
- (CGRect) pickerJointFrameWithSize

CGSize) size {
//CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGRect pickerRect = CGRectMake(60.0, 180, 200, 100); // x,y,w,h.
return pickerRect;
}
... and ...
- (void) createJointPicker {
myJointPicker = [[JointPicker alloc] init];
// Position the picker at the bottom.
myPickerView = [[UIPickerView alloc] initWithFrame:CGRectZero];
CGSize pickerSize = [myPickerView sizeThatFits:CGSizeZero];
myPickerView.frame = [self pickerJointFrameWithSize

ickerSize];
myPickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
myPickerView.delegate = myJointPicker;
myPickerView.showsSelectionIndicator = YES;
// Add picker to our view controller
myPickerView.hidden = NO;
[self.view addSubview:myPickerView];
}