根据indexPath更改键盘类型

时间:2013-01-14 08:04:37

标签: image cocoa-touch uitableview

我正在创建一个应用程序,其中有一个自定义UITableViewCell,它具有条件,然后是用户键入的答案。我想根据选择哪一行来更改键盘类型以方便用户。

例如。 “成本”行必须显示一个数字键盘键盘供用户输入,“郊区”行必须显示标准键盘供用户输入。

这是一个帮助你们的形象。此单元格需要标准键盘。

http://i.stack.imgur.com/rGFhC.png

2 个答案:

答案 0 :(得分:0)

这很简单。您可以像这样修改-cellForRowAtIndexPath:

if (indexPath.row == 1)
{
     [textField setKeyboardType:UIKeyboardTypeNumberPad];
}
else if ()
{
}..

某些键盘类型是:

UIKeyboardTypeDefault,                // Default type for the current input method.
UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.
UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).

答案 1 :(得分:0)

如果要在自定义单元格中放置文本字段以输入数据,则

if (indexPath.row == 1)
{
     textfield.keyboardType = UIKeyboardTypeNumberPad; //(for number keypad)
}

有不同的键盘类型。

对于标准键盘,请使用枚举UIKeyboardTypeDefault

In -cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath 
{

    UITableViewCell *cell = nil;

    static NSString *CellIdentifier = @"cellidentifier";

    CustomCell *tableCustomCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (tableCustomCell == nil)
    {
        [[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
        tableCustomCell = self.customCell;
        self.customCell = nil;
    }
    //Here add the check for the textfields


    cell = tableCustomCell;
    return cell;

}

希望这会对你有所帮助。