How to resize a UISwitch? - iphone

I have made a custom UISwitch (from this post). But the problem is, my custom texts are a bit long. Is there any way to resize the switch? [I tried setBounds, did not work]
Edit:
Here is the code I used:
#interface CustomUISwitch : UISwitch
- (void) setLeftLabelText: (NSString *) labelText;
- (void) setRightLabelText: (NSString *) labelText;
#end
#implementation CustomUISwitch
- (UIView *) slider
{
return [[self subviews] lastObject];
}
- (UIView *) textHolder
{
return [[[self slider] subviews] objectAtIndex:2];
}
- (UILabel *) leftLabel
{
return [[[self textHolder] subviews] objectAtIndex:0];
}
- (UILabel *) rightLabel
{
return [[[self textHolder] subviews] objectAtIndex:1];
}
- (void) setLeftLabelText: (NSString *) labelText
{
[[self leftLabel] setText:labelText];
}
- (void) setRightLabelText: (NSString *) labelText
{
[[self rightLabel] setText:labelText];
}
#end
mySwitch = [[CustomUISwitch alloc] initWithFrame:CGRectZero];
//Tried these, but did not work
//CGRect aFrame = mySwitch.frame;
//aFrame.size.width = 200;
//aFrame.size.height = 100;
//mySwitch.frame = aFrame;
[mySwitch setLeftLabelText: #"longValue1"];
[mySwitch setRightLabelText: #"longValue2"];

The simplest way is to resize it, as a view:
UISwitch *mySwitch = [[UISwitch alloc] init];
mySwitch.transform = CGAffineTransformMakeScale(0.75, 0.75);
and you don't have to care about anything else!

Here is the swift 3 version of mxg answer:
let mySwitch = UISwitch()
mySwitch.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)

Many controls are meant to be a specific size. If you were implementing this yourself, you would override setFrame:, adjust the frame parameter to match your control's required size, and then pass that to [super setFrame:].
If you subclass a control that has this behavior, there's really no way to override it because your subclass will inherit the superclass's implementation of setFrame:, which modifies your frame rectangle. And there's no way to set the frame of your control without calling [super setFrame:].
You'll most likely have to inherit from UIControl and implement the properties/behaviors you want from UISwitch manually to work around this.

UISwitch is not designed to be customized.
I think the your best solution is to download one of the custom switch implementations mentioned in the other question that you referred to. Either UICustomSwitch or RCSwitch. They both should be able to handle wide labels.

There is no option for resizing uiswitch in xib, so need to create and resize it in controller class,
UISwitch *onoff = [[UISwitch alloc] initWithFrame: CGRectMake(0, 0, 10, 10)];
onoff.transform = CGAffineTransformMakeScale(0.50, 0.50);
[self.view addSubview:onoff];

If you want to resize switch put through the Storyboard or nib, You can subclass UISwitch and override awakeFromNib method:
- (void)awakeFromNib {
self.transform = CGAffineTransformMakeScale(0.75, 0.75);
}
Select the switch control and change it's class to your custom switch class.

Here is a solution in code:
UISwitch *mySwitchNewsletter = [[UISwitch alloc] initWithFrame: CGRectMake(varSettingsSwitchNewsletter_x,
varSettingsSwitchNewsletter_y,
varSettingsSwitchNewsletter_width,
varSettingsSwitchNewsletter_height)];
if (mySwitchNewsletter != nil) {
[varCommerceSettingsView addSubview:mySwitchNewsletter];
float mySwitchScaleFactor = (varSettingsSwitchNewsletter_scale / 100.0);
CGFloat dX=mySwitchNewsletter.bounds.size.width/2, dY=mySwitchNewsletter.bounds.size.height/2;
mySwitchNewsletter.transform = CGAffineTransformTranslate(CGAffineTransformScale(CGAffineTransformMakeTranslation(-dX, -dY), mySwitchScaleFactor, mySwitchScaleFactor), dX, dY);
mySwitchNewsletter release];
}
Where varSettingsSwitchNewsletter_scale is an int from 0 to 100 (%).

// Just in case someone trying to hard code UISwitch in Xcode 6.4 the following is working
// in .h
#property UISwitch * onoff;
// in .m
self.onoff = [[UISwitch alloc] initWithFrame:CGRectMake(160, 40, 0, 0)];
_onoff.transform = CGAffineTransformMakeScale(0.50, 0.50);
[self.view addSubview:self.onoff];

Related

iOS SDK: UITableView Styling

I've searched high a low for a solution to this problem. I can't find why the style from my nib isn't loading? If I change anything in the nibs the functioning stops. So I've resorted to overriding the style.
I have:
- (id)initWithCoder:(NSCoder *)inCoder
{
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
// Custom initialization
}
return self;
}
This is on the second view controller, so following from rootviewcontroller. I would rather fix it another way, but if I have to override it I can.
So, the table is now grouped, but how can I programatically change the view background colour?
Any help appreciated.
Ps. For the initial problem, I have 3 nibs: MainWindow.xib, RootViewController.xib and CollectionsViewController.xib created by following this tutorial: http://www.techotopia.com/index.php/Creating_a_Navigation_based_iOS_4_iPhone_Application_using_TableViews#Setting_up_the_Data_in_the_Root_View_Controller
The first table is styled using the RootViewController.xib, but changing CollectionsViewController.xib does nothing.
Cheers,
Rhys
EDIT:
Got it with:
self.tableView.backgroundColor = [UIColor blackColor];
self.parentViewController.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.2 blue:0.5 alpha:0.7];
if you override initWithCoder: method, you must call it's super version, which one is responsible for decoding the nib file data
To change the background color of the Table view you need to redesign the table.
In your header viewcontroller add the following code and on IB connect the IBOutlet:
#interface TableController : UIViewController <UITableViewDelegate> {
UITableView *tableView;
}
#property (nonatomic, retain) IBOutlet UITableView *tableView;
and in your implementation file add on viewDidLoad:
- (void)viewDidLoad {
CGFloat tableBorderLeft = 25;
CGFloat tableBorderRight = 15;
CGFloat tableBorderUP = 10;
CGRect tableRect = self.view.frame;
tableRect.origin.x += tableBorderLeft; // make the table begin a few pixels right from its origin
tableRect.origin.y += tableBorderUP;
tableRect.size.width -= tableBorderLeft + tableBorderRight; // reduce the width of the table
tableView.frame = tableRect;
tableView.backgroundColor = [UIColor clearColor];
tableView.separatorColor = [UIColor whiteColor];
tableView.opaque = NO;
tableView.backgroundView = nil;
[super viewDidLoad];
}
Hope that works for you

How to achieve similar UI with UITextField inside UITableView (UITableViewCell)?

I am looking to mimic the following UI using a UITextField within a UITableViewCell (within a UITableView). I am new to MonoTouch and I can't seem to figure out what the code would look like for this.
This is very simple. Just add a UITextField with no background color to the cell. Add the below code in your cellForRowAtIndexPath method.
UITextField *inputText = [[UITextField alloc]initWithFrame:CGRectMake(10,10,280,22)];
inputText.textAlignment = UITextAlignmentLeft;
inputText.backgroundColor = [UIColor clearColor];
inputText.placeHolder = #"Street";
[cell.contentView addSubview:inputText];
[inputText release];
The cell is a custom cell. It has some properties, a editable UITextField, and a placehold string for empty content. The following code is writed by hand, so maybe there are some bugs inside.
#interface EditableCell : UITableViewCell {
UITextField *mTextField;
}
#property UITextField *textField;
- (void)setPlaceHoldString:(NSString *)placeHolder;
#end
#implement EditableCell
#synthesize textField = mTextField;
- (void)setPlaceHoldString:(NSString *)placeHolder
{
self.textField.placeHolder = placeHolder;
}
- (UITextField *)textField
{
if (mTextField == nil) {
mTextField = [[UITextField alloc] init];
// Configure this text field.
...
[self addSubView:mTextField];
}
return mTextField;
}
- (void)dealloc
{
self.textField = nil;
[super dealloc];
}
#end

Accessing View in awakeFromNib?

I have been trying to set a UIImageView background color (see below) in awakeFromNib
[imageView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
When it did not work, I realised that its probably because the view has not loaded yet and I should move the color change to viewDidLoad.
Can I just verify that I have this right?
gary
EDIT_002:
I have just started a fresh project to check this from a clean start. I setup the view the same as I always do. The results are that the controls are indeed set to (null) in the awakeFromNib. Here is what I have:
CODE:
#interface iPhone_TEST_AwakeFromNibViewController : UIViewController {
UILabel *myLabel;
UIImageView *myView;
}
#property(nonatomic, retain)IBOutlet UILabel *myLabel;
#property(nonatomic, retain)IBOutlet UIImageView *myView;
#end
.
#synthesize myLabel;
#synthesize myView;
-(void)awakeFromNib {
NSLog(#"awakeFromNib ...");
NSLog(#"myLabel: %#", [myLabel class]);
NSLog(#"myView : %#", [myView class]);
//[myLabel setText:#"AWAKE"];
[super awakeFromNib];
}
-(void)viewDidLoad {
NSLog(#"viewDidLoad ...");
NSLog(#"myLabel: %#", [myLabel class]);
NSLog(#"myView : %#", [myView class]);
//[myLabel setText:#"VIEW"];
[super viewDidLoad];
}
OUTPUT:
awakeFromNib ...
myLabel: (null)
myView : (null)
viewDidLoad ...
myLabel: UILabel
myLabel: UIImageView
I would be interested to know if this should work, from the docs it looks like it should, but given the way I usually set things up I can't quite understand why it does not in this case.
One more answer :-) It looks like you’re getting this behaviour because the controller loads the views lazily. The view is not loaded immediately, it gets loaded the first time somebody calls the view accessor. Therefore at the time you recieve awakeFromNib the NIB loading process is done, but not for the objects inside your views. See this code:
#property(retain) IBOutlet UILabel *foo;
#synthesize foo;
- (void) awakeFromNib
{
NSLog(#"#1: %i", !!foo);
[super awakeFromNib];
NSLog(#"#2: %i", !!foo);
}
- (void) viewDidLoad
{
NSLog(#"#3: %i", !!foo);
}
This logs:
#1: 0
#2: 0
#3: 1
But if you force-load the view:
- (void) awakeFromNib
{
NSLog(#"#1: %i", !!foo);
[super awakeFromNib];
[self view]; // forces view load
NSLog(#"#2: %i", !!foo);
}
The log changes into this:
#1: 0
#3: 1
#2: 1
I believe your call to super needs to be the first line in the awakeFromNib method, otherwise the elements won't be setup yet.
-(void)awakeFromNib {
[super awakeFromNib];
[imageView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[testLabel setText:#"Pants ..."];
}
I know, this post is a bit older, but I recently had a similar problem and would like to share its solution with you.
Having subclassed NSTextView, I wanted to display the row colors in alternating orders. To be able to alter the colors from outside, I added two instance vars to my subclass, XNSStripedTableView:
#interface XNSStripedTableView : NSTableView {
NSColor *pColor; // primary color
NSColor *sColor; // secondary color
}
#property (nonatomic, assign) NSColor *pColor;
#property (nonatomic, assign) NSColor *sColor;
#end
Overwriting highlightSelectionInClipRect: does the trick to set the correct color for the respective clipRect.
- (void)highlightSelectionInClipRect:(NSRect)clipRect
{
float rowHeight = [self rowHeight] + [self intercellSpacing].height;
NSRect visibleRect = [self visibleRect];
NSRect highlightRect;
highlightRect.origin = NSMakePoint(NSMinX(visibleRect), (int)(NSMinY(clipRect)/rowHeight)*rowHeight);
highlightRect.size = NSMakeSize(NSWidth(visibleRect), rowHeight - [self intercellSpacing].height);
while (NSMinY(highlightRect) < NSMaxY(clipRect)) {
NSRect clippedHighlightRect = NSIntersectionRect(highlightRect, clipRect);
int row = (int) ((NSMinY(highlightRect)+rowHeight/2.0)/rowHeight);
NSColor *rowColor = (0 == row % 2) ? sColor : pColor;
[rowColor set];
NSRectFill(clippedHighlightRect);
highlightRect.origin.y += rowHeight;
}
[super highlightSelectionInClipRect: clipRect];
}
The only problem now is, where to set the initial values for pColor and sColor? I tried awakeFromNib:, but this would cause the debugger to come up with an error. So I dug into the problem with NSLog: and found an easy but viable solution: setting the initial values in viewWillDraw:. As the objects are not created calling the method the first time, I had to check for nil.
- (void)viewWillDraw {
if ( pColor == nil )
pColor = [[NSColor colorWithSRGBRed:0.33 green:0.33 blue:0 alpha:1] retain];
if ( sColor == nil )
sColor = [[NSColor colorWithSRGBRed:0.66 green:0.66 blue:0 alpha:1] retain];
}
I do think this solution is quite nice :-) although one could reselect the names of pColor and sColor could be adjusted to be more "human readable".
Are you sure the objects are not nil? NSAssert or NSParameterAssert are your friends:
-(void) awakeFromNib {
NSParameterAssert(imageView);
NSParameterAssert(testLabel);
NSLog(#"awakeFromNib ...");
[imageView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0]];
[testLabel setText:#"Pants ..."];
[super awakeFromNib];
}
If the objects are really initialized, try to log their address and make sure that the instances that appear in viewDidLoad are the same as those in awakeFromNib:
- (void) awakeFromNib {
NSLog(#"test label #1: %#", testLabel);
}
- (void) viewDidLoad {
NSLog(#"test label #2: %#", testLabel);
}
If the numbers are the same, you can create a category to set a breakpoint on setBackgroundColor and peek in the stack trace to see what’s going on:
#implementation UIImageView (Patch)
- (void) setBackgroundColor: (UIColor*) whatever {
NSLog(#"Set a breakpoint here.");
}
#end
You can do the same trick using a custom subclass:
#interface PeekingView : UIImageView {}
#end
#implementation PeekingView
- (void) setBackgroundColor: (UIColor*) whatever {
NSLog(#"Set a breakpoint here.");
[super setBackgroundColor:whatever];
}
#end
Now you’ll set your UIViewObject to be of class PeekingView in the Interface Builder and you’ll know when anybody tries to set the background. This should catch the case where somebody overwrites the background changes after you initialize the view in awakeFromNib.
But I presume that the problem will be much more simple, ie. imageView is most probably nil.
In case you're using a UIView subclass instead of a UIViewController subclass, you can override loadView method:
- (void)loadView
{
[super loadView];
//IBOutlets are not nil here.
}

UISearchBar text color

Browsed the documentation and I couldn't find anything to change the color of UISearchBar. Does anybody know how to change it? There isn't any textColor property :/
Thx
Works on iOS 7 and later:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:#{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont systemFontOfSize:15]
}];
You may remove unused attribute as well.
UPDATE. Due to appearanceWhenContainedIn is deprecated in iOS 9, see the Dishant's answer below: https://stackoverflow.com/a/38893352/2799722
You can do the following: Just get the searchField property from the SearchBar, and then change its textColor property.
UITextField *searchField = [searchbar valueForKey:#"_searchField"];
searchField.textColor = [UIColor redColor]; //You can put any color here.
That's it! Now you manipulate the textField in any way possible.
iOS 8: See https://stackoverflow.com/a/28183058/308315
iOS 6 / 7:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor redColor]];
I suspect you could use techniques described in this post
Modifying the code presented there slightly, you subclass UISearchBar:
#interface SearchBar : UISearchBar {
}
#end
Then in your implementation:
- (void)layoutSubviews {
UITextField *searchField;
NSUInteger numViews = [self.subviews count];
for(int i = 0; i < numViews; i++) {
if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
searchField = [self.subviews objectAtIndex:i];
}
}
if(!(searchField == nil)) {
searchField.textColor = [UIColor redColor];
}
[super layoutSubviews];
}
I haven't tested either the original post's code or this code, but looks like it ought to work.
-wkw
Here's a category that adds this functionality:
#implementation UISearchBar (UISearchBar_TextColor)
- (UITextField *)field {
// HACK: This may not work in future iOS versions
for (UIView *subview in self.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
return (UITextField *)subview;
}
}
return nil;
}
- (UIColor *)textColor {
return self.field.textColor;
}
- (void)setTextColor:(UIColor *)color {
self.field.textColor = color;
}
#end
For iOS11, I found this worked:
After setting the searchController into the navigationItem, the search text was black on black. To make it white, I had to do:
searchController.searchBar.barStyle = .blackTranslucent
It was the only thing that worked for me. My app has a transparent navigation bar to let the background gradient show through, and I am guessing the SearchBar takes on that appearance since my appearance settings for UISearchBar were largely ignored with one exception:
UISearchBar.appearance().tintColor = UIColor.red
This made the Cancel button and the text insertion cursor red. The placeholder text was light gray.
Note that: UISearchBar.appearance().barStyle = .blackTranslucent did not work - it had to be set on the instance. This also had no visible effect on the search bar (it was still transparent like the navigation bar); it just made the search text white.
appearanceWhenContainedIn is deprecated in iOS 9 , so we have to use below method for iOS 9 and above.
[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:#[[UISearchBar class]]]
setTintColor:[UIColor whiteColor]];
With iOS 11 the search bar is expected to become part of the navigation bar which, as you might expect, adds all kinds of new "features."
I think it's a bug but I found that I needed to do the following to change the text (and cancel button) colour:
self.searchController.searchBar.barStyle = UISearchBarStyleMinimal;
[[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:#[[UISearchBar class]]]
setTintColor:[UIColor whiteColor]];
I found that the bar-style, when left to "default," would make the text black no matter the tint colour, etc. When set to either Minimal or Prominent the text was visible.
Here's a cleaner approach:
UITextField *searchField = nil;
for (UIView *v in self.searchBar.subviews)
{
if ([v isKindOfClass:[UITextField class]])
{
searchField = (UITextField *)v;
break;
}
}
if (searchField)
{
searchField.textColor = [UIColor whiteColor];
}
Modified the category suggested by David Foster (#david-foster) to work on iOS 8.
static UITextField *PBFindTextFieldInView(UIView *view) {
for(UIView *subview in view.subviews) {
if([subview isKindOfClass:UITextField.class]) {
return (UITextField *)subview;
} else {
UITextField* textField = PBFindTextFieldInView(subview);
if(textField) {
return textField;
}
}
}
return nil;
}
#implementation UISearchBar (Appearance)
- (UITextField *)field {
return PBFindTextFieldInView(self);
}
- (UIColor *)textColor {
return self.field.textColor;
}
- (void)setTextColor:(UIColor *)color {
self.field.textColor = color;
}
#end
After setting the searchController in the navigationItem for iOS 11, I found that attempting to set the textColor via UIAppearance for any UITextField within a UISearchBar had no affect, but a custom appearance property that simply called the regular textColor worked just fine.
// Implement a custom appearance property via a UITextField category
#interface UITextField (SearchBarTextColor)
#property (nonatomic, strong) UIColor * textColorWorkaround UI_APPEARANCE_SELECTOR;
#end
#implementation UITextField (SearchBarTextColor)
- (UIColor *)textColorWorkaround {
return self.textColor;
}
- (void)setTextColorWorkaround:(UIColor *)textColor {
self.textColor = textColor;
}
#end
And then use as follows:
UITextField *textFieldProxy = [UITextField appearanceWhenContainedInInstancesOfClasses:#[UISearchBar.class]];
textFieldProxy.textColorWorkaround = UIColor.lightGrayColor;
P.S. The same trick helped me color the seemingly inaccessible labels of UIDatePicker and UIPickerView

UIPickerView added to uitableviewcontroller.view won't rotate

I have a UIPickerView as subview in a UITableViewController, which I want to slide up in place when a certain row is clicked. I have implemented the necessary dataSource and delegate methods, but the pickerview acts weirdly. It acts as if it were mechanically jammed, it cannot rotate properly, it just moves a little. If I try to spin it a few times I get this message in the debugger console:
SendDelegateMessage: delegate failed
to return after waiting 10 seconds.
main run loop mode:
UITrackingRunLoopMode If you were not
using the touch screen for this entire
interval (which can prolong this
wait), please file a bug.
I googled for this, to no avail.
Anyway, here is the relevant code. As you may guess, this is a number picker (to choose a percentage value).
- (void)viewDidLoad {
[super viewDidLoad];
percentPicker = [[UIPickerViewalloc] initWithFrame:CGRectMake(0,420, 320, 200)];
percentPicker.delegate = self;
percentPicker.dataSource = self;
percentPicker.showsSelectionIndicator = YES;
[self.view addSubview:percentPicker];
}
- (void)viewWillAppear:(BOOL)animated {
// sets the rows to the appropriate value
// etc
}
- (void)startEditingPercentage {
[UIView beginAnimations :nilcontext:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:kPickerAnimationDuration ];
percentPicker.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, -220.0);
[UIViewcommitAnimations];
}
- (void)stopEditingPercentage {
NSLog(#"stopEditingPercentage");
[UIView beginAnimations :nilcontext:NULL];
[UIViewsetAnimationBeginsFromCurrentState:YES];
[UIViewsetAnimationDuration:kPickerAnimationDuration];
percentPicker.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
#pragma mark UIPickerView delegate and dataSource methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return4;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return10;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return44;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (UILabel *)view;
if (!retval) {
retval= [[UILabel newLabelWithPrimaryColor :[UIColorblackColor ] selectedColor:[ UIColor blackColor] fontSize:22bold:YEStransparent:YES] autorelease];
}
retval.frame = CGRectMake(0, 0, 44, 44);
retval.textAlignment = UITextAlignmentCenter;
retval.backgroundColor = [UIColor clearColor];
retval.text = [NSStringstringWithFormat:#"%i", row];
if (component > 1 ) {
// rows 2 and 3 are decimal, white on black
retval.backgroundColor = [UIColor blackColor];
retval.textColor = [UIColor whiteColor];
}
return retval;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSString *selectedValue;
selectedValue= [NSString stringWithFormat:#"%i%i.%i%i" ,[percentPickerselectedRowInComponent :0], [ percentPickerselectedRowInComponent: 1], [percentPickerselectedRowInComponent:2], [percentPickerselectedRowInComponent:3]];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSString *trimmedValue = [[formatter numberFromString:selectedValue] stringValue];
percentValue.text = trimmedValue;
[formatter release];
}
As you see, I use the transform property to move the picker in and out (down) my main view; the startEditing and stopEditing methods are triggered by selection in the teble view. Yet, for the debugging purposes, I eliminated these transitions , and left the picker on top of the table, but nothing changed. I also commented the didSelect method, but this also didn't change anything.
By the way, the same picker-view construction code vorkw allright in another view of the same app.
Any suggestion?
Cheers,
You aren't really adding the picker to UITableView using the code in viewDidLoad. UITableView can only have controls/rows in UITableViewCells and these are specified in the cellForRowAtIndex method. We cannot add controls to UITableView like we do to UIView.
Try using a subclass of UIView instead and add the UITableView and the picker to this UIView subclass.
In case you want to use a UITableViewController subclass only, create a custom cell and add the picker to this custom cell. But then you won't be able to hide/unhide this cell if you add it statically. Then you'll have to use reloadData. I would suggest using the UIView subclass.