views:

301

answers:

1

I'm looking for a non-hackish solution for this, so basically -inputView. The part that I'm not sure about is how to make it look like the regular keyboards, from the background to the keys. I realize that I could photoshop an apple keyboard, but this seems like it is a little hackish, especially if apple (probably not but still possible) decides to change the look of their keyboards. I know Numbers has done an excellent job of making extra keyboards that look like the standard system ones, and I would like to do it like those (although obviously they have access to the same resources that made the system keyboards, including possible private frameworks, etc.)

A: 

Create a view controller and xib. The xib should have 1-9,0 and delete buttons mapped to IBOutlets in your controller. Store and retain the return value string as a property. You can add decimals, etc. if you wish. In the header, store an edition block closure with a property (or alternatively create a delegate or use notification).

@property (copy) void(^valueChangedBlock)(NSString* string);

On touch up, each button sends an event to a method like this:

- (IBAction) pressKey:(id)sender
{
    NSString *toAppend;

    // Instead of this switch you can store the values in a dictionary mapped by sender.
    switch(sender)
    {
        case oneButton: toAppend=@"1"; break;
        case twoButton: toAppend=@"2"; break;
        ...
    }

    returnValue = [returnValue appendString:toAppend];
    valueChanged(returnValue);
}

Obviously the delete key should remove a character from the end of the string instead of appending. Other than creating the controller and adding this view as the inputView, you should add the valueChangedBlock and set it to update the text field. You may want to put a clear custom button over the text field set to make the field first responder so it doesn't appear as if the user can edit at any point in the string.

Peter DeWeese