Programmatically setting UIKeyboardType


#1

After reading a past post, I was curious as to when to properly set the keyboard type programmatically.

Although setting the keyboard type in -viewWillAppear: works properly, I think that setting the type in -viewDidLoad is better.

It is at this point that the view has been loaded and the outlets connected. It follows then that any manipulation of the view that is not contingent on another object or objects should be reconciled here. It is in this fashion that we set the background color of the ItemDetailViewController view.

-(void)viewDidLoad
{
    [super viewDidLoad];
    [[self view] setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    [valueField setKeyboardType:UIKeyboardTypeNumberPad];
}

Although setting the keyboard type in -viewWillAppear: works properly, it adds to the potential complexity of this method. Separating the contingent and non-contingent view manipulations lessens this complexity and may allow for “easier” debugging in the future.

I’m not sure whether or not this is the proper way to implement a keyboard type programmatically. If anyone has information otherwise or a better way to do so, please let me know! I’m still learning and thinking.